f32
IEEE-754 binary32 floating point with 24 bits of significand precision.
These examples describe the Development language contract. They are not a claim that every workflow is supported by the current public preview. Declaration excerpts belong inside a function unless a full module is shown.
Format, precision and finite range
f32 uses IEEE-754 binary32: 32 bits (4 bytes), with 24 significand bits including the implicit leading bit. Its greatest finite magnitude is 3.4028234663852886e38 (decimal approximation except f16’s exact 65504). The exact maximum is (2 - 2^(1-24)) × 2^127; the finite range is negative maximum through positive maximum. The smallest positive normal is 2^-126 (about 1.1754943508222875e-38); the smallest positive subnormal is 2^-149 (about 1.401298464324817e-45). Values between representable numbers round; this is not continuous real arithmetic. Every integer from -2^24 through 2^24 is exactly representable; larger integers may skip values.
let Maximum: f32 = 3.40282346638528859811704183484516925440e38_f32;
let SmallestNormal: f32 = 1.1754943508222875e-38_f32;
let SmallestSubnormal: f32 = 1.401298464324817e-45_f32;Literals and rounding
Use _f32 or a f32 context. An unconstrained floating literal defaults to f64. Decimal rounding is nearest, ties to even. Explicit literal construction rejects a finite literal outside the destination finite range. The spacing from 1 to its next representable larger value is 2^-23; precision is relative to magnitude. Neither decimal 0.1 nor most other decimal fractions has an exact binary representation.
let Half: f32 = 0.5;
let Explicit = 1.25_f32;
let Decimal: f32 = 0.1;
let WithExponent: f32 = 1.25e2;Special values and arithmetic
f32 includes positive/negative zero, positive/negative infinity and NaN, in addition to finite normal/subnormal values. Subnormals are preserved by default. Operators are unary +/-, +, -, *, / and IEEE comparisons; % is not provided. Floating division by zero produces IEEE infinity or NaN rather than the integer zero-divisor trap. NaN compares unequal to itself; every ordered comparison with NaN is false. +0 equals -0. Comparison sites receive Sn’s floating-comparison warning. Optimization level alone does not enable reassociation, fast-math, implicit FMA contraction or flushing subnormals. NaN payloads are unspecified.
// Inside a function; IEEE comparisons intentionally illustrate W2101.
let One: f32 = 1.0;
let Zero: f32 = 0.0;
let Infinity = One / Zero;
let NotANumber = Zero / Zero;
let IsNaN = NotANumber != NotANumber; // trueConversions
Implicit float widening follows f16 → f32 → f64. There is no implicit integer/float conversion. Explicit narrowing and integer-to-float conversion round nearest-even; precision loss is allowed, but a finite source whose rounded magnitude exceeds the finite range fails. Float-to-integer conversion truncates toward zero, rejects NaN/infinity, and checks the integer range. as traps on failure; as? returns none. round<I> instead rounds to the nearest integer with ties to even before checking its range.
let Value: f32 = 42.75;
let Truncated: i32 = Value as i32; // 42
let Rounded: i32 = round<i32>(Value); // 43
let Maybe: i32? = Value as? i32;
let Narrow: f16? = Value as? f16;See all primitive types and literals and user-defined suffixes.