diff options
| author | viri <hi@viri.moe> | 2022-04-06 20:49:05 -0600 |
|---|---|---|
| committer | viri <hi@viri.moe> | 2022-04-07 05:04:38 -0600 |
| commit | e46c61250332e615afc5aed6e4ebe57b8e6713eb (patch) | |
| tree | 5ffbc2acac6c03becd253c7d4308eb33a4721025 /lib/std/math/ldexp.zig | |
| parent | 5d6a5a123676ada3ccd229f31dc8855aabaf8057 (diff) | |
| download | zig-e46c61250332e615afc5aed6e4ebe57b8e6713eb.tar.gz zig-e46c61250332e615afc5aed6e4ebe57b8e6713eb.zip | |
use math/float.zig everywhere
Diffstat (limited to 'lib/std/math/ldexp.zig')
| -rw-r--r-- | lib/std/math/ldexp.zig | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/std/math/ldexp.zig b/lib/std/math/ldexp.zig index f8ab237fad..0934244c65 100644 --- a/lib/std/math/ldexp.zig +++ b/lib/std/math/ldexp.zig @@ -57,6 +57,8 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) { } test "math.ldexp" { + // TODO derive the various constants here with new maths API + // basic usage try expect(ldexp(@as(f16, 1.5), 4) == 24.0); try expect(ldexp(@as(f32, 1.5), 4) == 24.0); @@ -73,20 +75,20 @@ test "math.ldexp" { try expect(math.isNormal(ldexp(@as(f128, 1.0), -16382))); try expect(!math.isNormal(ldexp(@as(f128, 1.0), -16383))); // unreliable due to lack of native f16 support, see talk on PR #8733 - // try expect(ldexp(@as(f16, 0x1.1FFp-1), -14 - 9) == math.f16_true_min); - try expect(ldexp(@as(f32, 0x1.3FFFFFp-1), -126 - 22) == math.f32_true_min); - try expect(ldexp(@as(f64, 0x1.7FFFFFFFFFFFFp-1), -1022 - 51) == math.f64_true_min); - try expect(ldexp(@as(f128, 0x1.7FFFFFFFFFFFFFFFFFFFFFFFFFFFp-1), -16382 - 111) == math.f128_true_min); + // try expect(ldexp(@as(f16, 0x1.1FFp-1), -14 - 9) == math.floatTrueMin(f16)); + try expect(ldexp(@as(f32, 0x1.3FFFFFp-1), -126 - 22) == math.floatTrueMin(f32)); + try expect(ldexp(@as(f64, 0x1.7FFFFFFFFFFFFp-1), -1022 - 51) == math.floatTrueMin(f64)); + try expect(ldexp(@as(f128, 0x1.7FFFFFFFFFFFFFFFFFFFFFFFFFFFp-1), -16382 - 111) == math.floatTrueMin(f128)); // float limits - try expect(ldexp(@as(f32, math.f32_max), -128 - 149) > 0.0); - try expect(ldexp(@as(f32, math.f32_max), -128 - 149 - 1) == 0.0); - try expect(!math.isPositiveInf(ldexp(@as(f16, math.f16_true_min), 15 + 24))); - try expect(math.isPositiveInf(ldexp(@as(f16, math.f16_true_min), 15 + 24 + 1))); - try expect(!math.isPositiveInf(ldexp(@as(f32, math.f32_true_min), 127 + 149))); - try expect(math.isPositiveInf(ldexp(@as(f32, math.f32_true_min), 127 + 149 + 1))); - try expect(!math.isPositiveInf(ldexp(@as(f64, math.f64_true_min), 1023 + 1074))); - try expect(math.isPositiveInf(ldexp(@as(f64, math.f64_true_min), 1023 + 1074 + 1))); - try expect(!math.isPositiveInf(ldexp(@as(f128, math.f128_true_min), 16383 + 16494))); - try expect(math.isPositiveInf(ldexp(@as(f128, math.f128_true_min), 16383 + 16494 + 1))); + try expect(ldexp(math.floatMax(f32), -128 - 149) > 0.0); + try expect(ldexp(math.floatMax(f32), -128 - 149 - 1) == 0.0); + try expect(!math.isPositiveInf(ldexp(math.floatTrueMin(f16), 15 + 24))); + try expect(math.isPositiveInf(ldexp(math.floatTrueMin(f16), 15 + 24 + 1))); + try expect(!math.isPositiveInf(ldexp(math.floatTrueMin(f32), 127 + 149))); + try expect(math.isPositiveInf(ldexp(math.floatTrueMin(f32), 127 + 149 + 1))); + try expect(!math.isPositiveInf(ldexp(math.floatTrueMin(f64), 1023 + 1074))); + try expect(math.isPositiveInf(ldexp(math.floatTrueMin(f64), 1023 + 1074 + 1))); + try expect(!math.isPositiveInf(ldexp(math.floatTrueMin(f128), 16383 + 16494))); + try expect(math.isPositiveInf(ldexp(math.floatTrueMin(f128), 16383 + 16494 + 1))); } |
