Implemented by the primary BASIL compiler; the frozen Rust seed remains unchanged. DOUBLE is IEEE-754 binary64. Decimal literals include 1.5, .5, 1., and 6.02e23. An exponent makes a literal floating point even without a decimal point. Decimal conversion rounds to nearest, ties to even, including subnormals. A literal that overflows is rejected; underflow can round to signed zero. SINGLE and decimal/fixed-point types are not implemented.
DIM measurements = [1.5, 2.5, 3.5]
DIM total = 0.0
FOR EACH value IN measurements
total = total + value
NEXT
PRINT total / CDBL(LEN(measurements))
PRINT SQRT(2.0)
PRINT POW(2.0, 10.0)
PRINT IsNaN(SQRT(-1.0)) ' TRUE; math itself does not raise an error.
TRY
PRINT Finite(EXP(1000.0))
CATCH problem AS NonFiniteError
PRINT "Expected a finite value: ";problem.Value
END TRYThere are no implicit INTEGER/DOUBLE conversions, including in collections and overload resolution. CDBL(integer) converts with nearest-even rounding. CDBL(double) preserves the input bits. TRY CINT(double) truncates toward zero and reports NumericError { Code=2 } for nonfinite or out-of-range values. TRY CDBL(text) / TRY VALDOUBLE(text) trim Unicode whitespace and parse the entire ASCII numeric spelling; malformed text reports NumericError code 1, finite overflow code 2. Signed inf, infinity, and nan are accepted. STR(double) and PRINT use a shortest round-tripping decimal spelling. Negative zero prints -0.0.
Arithmetic + - * /, unary signs, and comparisons accept matching DOUBLE operands. Arithmetic follows IEEE behavior, including infinities, NaNs, gradual underflow, and signed zero. Division by floating zero does not become an integer arithmetic trap. NaN compares unequal to every value, including itself; all ordered comparisons involving NaN are false. MOD remains an integer operation; use FMOD or REMAINDER for doubles. POW provides exponentiation; a ^ operator is not implemented.
Defaults can contain DOUBLE literals and constant arithmetic/comparisons. Floating division by zero in a default has the same IEEE result as runtime arithmetic. Mixed numeric types are rejected in defaults as elsewhere.
Functions
Names are case-insensitive. Unless noted, arguments and numeric results are DOUBLE. Floating math functions are infallible: numeric domain failures return NaN; overflow returns signed infinity; underflow rounds normally, possibly to signed zero. There is no mandatory result-validation pass. Algorithms retain the input classification needed for correct special cases and safe range reduction. Allocation failure is fatal and separate.
Use Finite(value AS DOUBLE) AS DOUBLE FAILS NonFiniteError to opt into finite-result
validation. It returns a finite input bit-for-bit, including signed zeros/subnormals,
or returns NonFiniteError {Value AS DOUBLE} with the rejected bits. It uses ordinary
CATCH/FAILS propagation and automatic cleanup, including in tasks. IsFinite is the
non-failing predicate. Finite checks only its supplied result: finite underflow and
1.0/Infinity() pass. No hardware trap modes are changed.
| Family | Functions | Contract |
|---|---|---|
| Constants/classification | PI(), TAU(), E(), Infinity(), NaN(), IsNaN(x), IsInfinite(x), IsFinite(x) | Infallible; IsInfinite accepts either infinity sign |
| Explicit validation | Finite(x) | NonFiniteError for NaN or either infinity |
| Magnitude/sign | ABS(x), COPYSIGN(x,sign) | Infallible |
| Sign as INTEGER | SGN(x), SIGN(x) | DOUBLE NaN fails MathError code 1; INTEGER overloads infallible |
| INTEGER magnitude | ABS(integer) | NumericError code 2 for minimum INTEGER |
| Rounding, DOUBLE result | TRUNC/FIX, FLOOR/INT, CEIL/CEILING, ROUND(x) | Infallible; ROUND ties to even |
| Decimal-place rounding | ROUND(x,places AS INTEGER) | Infallible; exact decimal quantization of binary input, ties to even; overflow to signed infinity |
| Bounds | MIN(a,b), MAX(a,b), CLAMP(x,lower,upper), also INTEGER overloads | DOUBLE CLAMP returns NaN for reversed/NaN bounds; INTEGER CLAMP fails MathError code 1 for reversed bounds |
| Roots/power | SQR/SQRT(x), POW(base,exponent), EXP2(x), HYPOT(x,y), CBRT(x) | Infallible |
| Exponential/log | EXP, EXPM1, LOG/LN, LOG(x,base), LOG2, LOG10, LOG1P | Infallible |
| Trigonometric, radians | SIN, COS, TAN, ASIN, ACOS, ATAN/ATN, ATAN2(y,x) | Infallible |
| Hyperbolic | SINH, COSH, ACOSH, ATANH, TANH, ASINH | Infallible |
| Angle conversion | DEGREES, RADIANS | Infallible |
| Fused operation | FMA(x,y,z) | Infallible; one final binary64 rounding for finite inputs; invalid infinite operations return NaN |
| Remainders | FMOD(x,y), REMAINDER(x,y) | Infallible; truncating versus nearest-even quotient |
| Binary scaling | LDEXP(x,exponent AS INTEGER) | Infallible; overflow to signed infinity |
| Binary decomposition | FREXP(x) returns FloatParts { Mantissa AS DOUBLE, Exponent AS INTEGER } | Infallible |
| Adjacent values | NEXTAFTER(x,toward), ULP(x) | Infallible |
| Bit serialization | DoubleBits(x) returns INTEGER; DoubleFromBits(integer) | Infallible; numeric encodings, never addresses |
Important special cases:
| Operation | Result |
|---|---|
| SQR/SQRT(negative), LOG/LN/LOG2/LOG10(negative) | NaN |
| LOG/LN/LOG2/LOG10(+0 or -0), LOG1P(-1) | Negative infinity |
| LOG1P(x < -1), LOG(x,base <= 0 or base = 1) | NaN |
| ASIN/ACOS outside [-1,1], ACOSH below 1 | NaN |
| ATANH(+1), ATANH(-1), ATANH outside [-1,1] | Positive infinity, negative infinity, NaN respectively |
| Finite negative POW base with nonintegral exponent | NaN |
| POW(+0,negative), POW(-0,negative odd integer) | Positive infinity, negative infinity respectively |
| POW(x,0), POW(1,x), including NaN arguments | 1.0 |
| SIN/COS/TAN(infinity) | NaN |
| FMOD/REMAINDER with zero divisor or infinite dividend | NaN |
| HYPOT(infinity,NaN) | Positive infinity |
NaNs otherwise propagate; no payload/sign is promised for computed NaNs. Explicit bit conversion and successful/rejected Finite values preserve their input bits. Legacy inline TRY is accepted only for fallible calls: remove it from calls to the now-infallible floating math functions. TRY blocks remain useful around Finite and numeric conversions. MathError now covers INTEGER-result sign and INTEGER bound errors; it no longer reports floating numeric domain or overflow results.
MIN/MAX propagate NaNs and select the appropriate signed zero. CBRT handles negative numbers. Trigonometric reduction covers the full finite binary64 range. No application cleanup is promised after fatal allocation failure.
Collections
DOUBLE works in records, optionals and collections. Scalar and recursive equality follow IEEE rules: NaN is unequal even inside a value compared with itself. Compare returns CompareResult.Unordered; default stable sorting uses separate NaNs-last ordering. NaN set members/dictionary keys are rejected through checked InvalidKeyError, including composite keys; list elements and dictionary values may contain NaN. Infinity is valid and signed zeros are equal with equal hashes. Comparison, sorting, key and error contracts .