float64
| Property | Value |
|---|---|
| Size | 8 bytes (64 bits) |
| Format | IEEE 754 binary64 (double precision) |
| Approximate range | ±2.2 × 10-308 to ±1.8 × 10308 |
| Decimal precision | ~15–16 digits |
| Literal suffix | f64 |
| Hardware support | Native on all supported targets |
float64 is the default floating-point type in Rux — float is a built-in alias for it. It is fully IEEE 754-2019 compliant. Special values (Inf, -Inf, NaN) are supported, and division by zero produces Inf or NaN rather than a fatal error.
Literals
A floating-point literal written without an annotation or suffix is inferred as float64:
let e = 2.718281828459045; // float64 (inferred)
let a: float64 = 1.0; // explicit annotation
let b = 1.0f64; // type suffixDecimal and scientific forms are both accepted:
let avogadro = 6.022e23; // 6.022 × 10²³
let planck = 6.626e-34; // 6.626 × 10⁻³⁴See Literals for the full grammar.
Typical Use Cases
- Scientific computing
- Financial calculations
- General-purpose numeric code
Arithmetic
| Operator | Description | Compound |
|---|---|---|
+ | Addition | += |
- | Subtraction | -= |
* | Multiplication | *= |
/ | Division | /= |
% | Remainder | %= |
** | Exponentiation | n/a |
let a: float64 = 10.0;
let b: float64 = 3.0;
let sum = a + b; // 13.0
let quot = a / b; // 3.3333333333333335
let rem = a % b; // 1.0Both operands must share the same type; mixed-width expressions require an explicit cast. Arithmetic rounds to nearest (ties to even), unary negation (-x) flips the sign, and results that exceed the range overflow to Inf. Subtracting nearly equal values loses significant digits (catastrophic cancellation) — reorder the computation or use a wider type when accuracy matters.
Division by zero never fails: it yields signed infinity, and 0.0 / 0.0 yields NaN. Inf and NaN then propagate — Inf - Inf and Inf * 0.0 are both NaN.
let p = 1.0 / 0.0; // Inf
let n = -1.0 / 0.0; // -Inf
let u = 0.0 / 0.0; // NaNComparison
| Operator | Description | Result |
|---|---|---|
== | Equal | bool |
!= | Not equal | bool |
< | Less than | bool |
<= | Less than or equal | bool |
> | Greater than | bool |
>= | Greater than or equal | bool |
Both operands must have the same type; comparing a different float width, or a float with an integer, is a compile-time error — cast explicitly first.
NaN is unordered: every comparison involving it returns false, including NaN == NaN. Detect it with IsNan, never ==. For the same reason, avoid == between computed results and compare within a tolerance instead:
let x = 0.1 + 0.2;
let close = Abs(x - 0.3) < 1.0e-9; // not x == 0.3Conversion
Rux implicitly widens to any larger float type, so no precision is lost. Narrowing must be explicit and rounds to nearest (ties to even).
let x: float64 = 1.5;
let wide: float128 = x; // widening — implicit
let narrow = x as float32; // narrowing — explicit castFloat-to-integer conversions are always explicit and truncate toward zero; the reverse (int→float) widens implicitly. Casting NaN or Inf to an integer raises a fatal error in debug builds.
let whole = x as int32; // 1 truncates toward zero
let back: float64 = 100; // 100.0 int→float, implicit