test(lang): pin f64.min via signed union bit view in example 0159 [NL.2]

This commit is contained in:
agra
2026-06-05 00:35:52 +03:00
parent 6478ccbe3c
commit bdf6433e72
2 changed files with 10 additions and 4 deletions

View File

@@ -25,10 +25,11 @@
#import "modules/std.sx";
// `bits` mirrors each float's raw IEEE-754 storage. f64 needs 64 bits, f32 32.
// The f64 union uses a `u64` view so the all-ones-ish positive patterns read as
// their true magnitude; the negative `f64.min` pattern (0xFFEF…) overflows the
// i64 literal parser, so it is pinned by the `min == -max` property instead.
Uf64 :: union { f: f64; bits: u64; }
// The f64 union's `bits` (u64) view reads the all-ones-ish positive patterns as
// their true magnitude; its `s` (s64) view pins the negative `f64.min` pattern
// (0xFFEF…), whose unsigned form overflows the u64 literal parser, by comparing
// the signed reinterpret to -4503599627370497.
Uf64 :: union { f: f64; bits: u64; s: s64; }
Uf32 :: union { f: f32; bits: u32; }
main :: () -> s32 {
@@ -43,6 +44,10 @@ main :: () -> s32 {
o.f = f64.max;
print("f64.max {}\n", o.bits == 0x7FEFFFFFFFFFFFFF); // true
// f64.min = -max; its bit pattern 0xFFEFFFFFFFFFFFFF overflows an unsigned u64
// literal, so it is pinned directly via the SIGNED s64 view: -4503599627370497.
o.f = f64.min;
print("f64.min {}\n", o.s == -4503599627370497); // true (bits 0xFFEFFFFFFFFFFFFF)
o.f = f64.epsilon;
print("f64.epsilon {}\n", o.bits == 0x3CB0000000000000); // true
o.f = f64.min_positive;

View File

@@ -1,5 +1,6 @@
f64.true_min true
f64.max true
f64.min true
f64.epsilon true
f64.min_positive true
f64.inf true