authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-10-09 17:12:31-07:00
committergravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-10-09 20:29:30-07:00
log879fb0c57cb483317ba671352144792e6d674779
treefedd6372c34a8f2f4297f59ef0beb17a5bb385b2
parentc9ecf7b920f1e5b7aa2366e83f722de46813ace3

Manually construct denormal constants in tests

Constructing these at runtime can cause them to be flushed to zero, which was triggering a CI failure for Windows.

1 files changed, 9 insertions(+), 3 deletions(-)

lib/std/math/ldexp.zig+9-3
......@@ -102,10 +102,16 @@ test "math.ldexp" {
102102 try expect(ldexp(math.floatTrueMin(T), 0) > 0.0);
103103 try expect(ldexp(math.floatTrueMin(T), -1) == 0.0);
104104
105 // Multiplications might flush the denormals to zero, esp. at
106 // runtime, so we manually construct the constants here instead.
107 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
108 const EightTimesTrueMin = @bitCast(T, @as(Z, 8));
109 const TwoTimesTrueMin = @bitCast(T, @as(Z, 2));
110
105111 // subnormals -> subnormals
106 try expect(ldexp(math.floatTrueMin(T), 3) == math.floatTrueMin(T) * 8);
107 try expect(ldexp(math.floatTrueMin(T) * 8, -2) == math.floatTrueMin(T) * 2);
108 try expect(ldexp(math.floatTrueMin(T) * 8, -3) == math.floatTrueMin(T));
112 try expect(ldexp(math.floatTrueMin(T), 3) == EightTimesTrueMin);
113 try expect(ldexp(EightTimesTrueMin, -2) == TwoTimesTrueMin);
114 try expect(ldexp(EightTimesTrueMin, -3) == math.floatTrueMin(T));
109115
110116 // subnormals -> normals (+)
111117 try expect(ldexp(math.floatTrueMin(T), fractional_bits) == math.floatMin(T));