std/numeric/ieee
std/ieee — IEEE-754 encoding primitives, at both widths.
Everything here reads or mints a float's [ sign | exponent | mantissa ]
pattern rather than computing with the value. Two operations, each in
both widths: __fNMagnitude reads the encoding out with the sign bit
cleared, __fNFromBits mints a float from an exact pattern. The
classification predicates and the special constants of std/numeric/math
(f64) and of std/text/boxing's Float facade (f32) are the callers.
Why the encoding and not the arithmetic. The classification predicates
are stated on the bits, and that is a correctness requirement rather than
a style preference. The arithmetic forms — x != x for a NaN,(x - x) != 0.0 for an infinity — ask the FPU about values thatFpMode::Fast tells LLVM do not exist: under nnan / ninf the compiler
is entitled to fold both to false, and a predicate whose whole job is to
detect those values would answer "no" for every input, silently. There is
no float instruction here to carry such a flag.bits & ~sign orders the encoding: everything below the infinity pattern
is finite, the pattern itself is an infinity, everything above is a NaN.
One mask and one comparison each, no branch, no exclusion step.
Why one module for both widths. The two widths are the same mechanism
at two sizes — the reinterpret, the mask, and the ordering argument above
are width-independent. Split across the modules that consume them, the
argument is restated once per width, and a correction lands on one copy.
Free functions
| Type | Method and description |
|---|---|
| __f64Magnitude(x : f64) : i64 The [ sign | exponent | mantissa ] pattern of x, sign bit cleared —the inverse of [ __f64FromBits].The stack slot's address read back as ptr<i64> is the reinterpret: theonly way to bit-cast f64 → i64 without a dedicated intrinsic. No heap,no copy — the compiler owns the slot. |
| __f64FromBits(bits : i64) : f64 Reinterpret the 64-bit pattern bits as an f64 (no value conversion) —the inverse of [ __f64Magnitude], and what mints the numeric bounds( math::f64PositiveInfinity() and friends) from their exact patterns. |
| __f64IsNaN(x : f64) : bool x.isNaN() — exponent all ones and a mantissa that is not zero. |
| __f64IsFinite(x : f64) : bool x.isFinite() — anything the exponent does not saturate. |
| __f64IsInfinite(x : f64) : bool x.isInfinite() — exponent all ones, mantissa zero, either sign. |
| __f32Magnitude(v : f32) : i32 The [ sign | exponent | mantissa ] pattern of v, sign bit cleared —the inverse of [ __f32FromBits], and the f32 twin of[ __f64Magnitude] (f32 and i32 are both 4-byte stack slots). |
| __f32FromBits(bits : i32) : f32 Reinterpret the 32-bit pattern bits as an f32 — the f32 twin of[ __f64FromBits], and what mints the Float facade's special constants. |
| __f32IsNaN(v : f32) : bool v.isNaN() — exponent all ones and a mantissa that is not zero. |
| __f32IsFinite(v : f32) : bool v.isFinite() — anything the exponent does not saturate. |
| __f32IsInfinite(v : f32) : bool v.isInfinite() — exponent all ones, mantissa zero, either sign. |
Method detail
#__f64Magnitude
The [ sign | exponent | mantissa ] pattern of x, sign bit cleared —
the inverse of [__f64FromBits].
The stack slot's address read back as ptr<i64> is the reinterpret: the
only way to bit-cast f64 → i64 without a dedicated intrinsic. No heap,
no copy — the compiler owns the slot.
x value whose encoding is read#__f64FromBits
Reinterpret the 64-bit pattern bits as an f64 (no value conversion) —
the inverse of [__f64Magnitude], and what mints the numeric bounds
(math::f64PositiveInfinity() and friends) from their exact patterns.
bits raw 64-bit IEEE-754 pattern to reinterpret as f64#__f64IsNaN
x.isNaN() — exponent all ones and a mantissa that is not zero.
#__f64IsFinite
x.isFinite() — anything the exponent does not saturate.
#__f64IsInfinite
x.isInfinite() — exponent all ones, mantissa zero, either sign.
#__f32Magnitude
The [ sign | exponent | mantissa ] pattern of v, sign bit cleared —
the inverse of [__f32FromBits], and the f32 twin of
[__f64Magnitude] (f32 and i32 are both 4-byte stack slots).
v value whose encoding is read#__f32FromBits
Reinterpret the 32-bit pattern bits as an f32 — the f32 twin of
[__f64FromBits], and what mints the Float facade's special constants.
bits raw 32-bit IEEE-754 pattern to reinterpret as f32#__f32IsNaN
v.isNaN() — exponent all ones and a mantissa that is not zero.
#__f32IsFinite
v.isFinite() — anything the exponent does not saturate.
#__f32IsInfinite
v.isInfinite() — exponent all ones, mantissa zero, either sign.