| ... | @@ -102,10 +102,16 @@ test "math.ldexp" { | ... | @@ -102,10 +102,16 @@ test "math.ldexp" { |
| 102 | try expect(ldexp(math.floatTrueMin(T), 0) > 0.0); | 102 | try expect(ldexp(math.floatTrueMin(T), 0) > 0.0); |
| 103 | try expect(ldexp(math.floatTrueMin(T), -1) == 0.0); | 103 | try expect(ldexp(math.floatTrueMin(T), -1) == 0.0); |
| 104 | | 104 | |
| | 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 | |
| 105 | // subnormals -> subnormals | 111 | // subnormals -> subnormals |
| 106 | try expect(ldexp(math.floatTrueMin(T), 3) == math.floatTrueMin(T) * 8); | 112 | try expect(ldexp(math.floatTrueMin(T), 3) == EightTimesTrueMin); |
| 107 | try expect(ldexp(math.floatTrueMin(T) * 8, -2) == math.floatTrueMin(T) * 2); | 113 | try expect(ldexp(EightTimesTrueMin, -2) == TwoTimesTrueMin); |
| 108 | try expect(ldexp(math.floatTrueMin(T) * 8, -3) == math.floatTrueMin(T)); | 114 | try expect(ldexp(EightTimesTrueMin, -3) == math.floatTrueMin(T)); |
| 109 | | 115 | |
| 110 | // subnormals -> normals (+) | 116 | // subnormals -> normals (+) |
| 111 | try expect(ldexp(math.floatTrueMin(T), fractional_bits) == math.floatMin(T)); | 117 | try expect(ldexp(math.floatTrueMin(T), fractional_bits) == math.floatMin(T)); |