From 879fb0c57cb483317ba671352144792e6d674779 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Sun, 9 Oct 2022 17:12:31 -0700 Subject: [PATCH] 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. --- lib/std/math/ldexp.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/std/math/ldexp.zig b/lib/std/math/ldexp.zig index b164b19aad..d2fd8db9b7 100644 --- a/lib/std/math/ldexp.zig +++ b/lib/std/math/ldexp.zig @@ -102,10 +102,16 @@ test "math.ldexp" { try expect(ldexp(math.floatTrueMin(T), 0) > 0.0); try expect(ldexp(math.floatTrueMin(T), -1) == 0.0); + // Multiplications might flush the denormals to zero, esp. at + // runtime, so we manually construct the constants here instead. + const Z = std.meta.Int(.unsigned, @bitSizeOf(T)); + const EightTimesTrueMin = @bitCast(T, @as(Z, 8)); + const TwoTimesTrueMin = @bitCast(T, @as(Z, 2)); + // subnormals -> subnormals - try expect(ldexp(math.floatTrueMin(T), 3) == math.floatTrueMin(T) * 8); - try expect(ldexp(math.floatTrueMin(T) * 8, -2) == math.floatTrueMin(T) * 2); - try expect(ldexp(math.floatTrueMin(T) * 8, -3) == math.floatTrueMin(T)); + try expect(ldexp(math.floatTrueMin(T), 3) == EightTimesTrueMin); + try expect(ldexp(EightTimesTrueMin, -2) == TwoTimesTrueMin); + try expect(ldexp(EightTimesTrueMin, -3) == math.floatTrueMin(T)); // subnormals -> normals (+) try expect(ldexp(math.floatTrueMin(T), fractional_bits) == math.floatMin(T));