diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-04-12 06:37:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-12 06:37:12 -0400 |
| commit | 17631cb2d30bf2d7b10401cf8f784a599bade5c5 (patch) | |
| tree | 8ba131f77ef38c531711c7b1147c59e993cab628 /lib/std/math/floor.zig | |
| parent | 17daba1806896a2e45a2c1b1969a540f44a64d86 (diff) | |
| parent | 9b5c02022f997d01bcfcfd79ba4c721af1bd9a6c (diff) | |
| download | zig-17631cb2d30bf2d7b10401cf8f784a599bade5c5.tar.gz zig-17631cb2d30bf2d7b10401cf8f784a599bade5c5.zip | |
Merge pull request #11401 from viriuwu/float-category-misc
math: simplify inf (+f80 support), deprecate old constants (followup for #10133)
Diffstat (limited to 'lib/std/math/floor.zig')
| -rw-r--r-- | lib/std/math/floor.zig | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig index d6761ba77e..ab5ca3583b 100644 --- a/lib/std/math/floor.zig +++ b/lib/std/math/floor.zig @@ -98,6 +98,8 @@ fn floor32(x: f32) f32 { } fn floor64(x: f64) f64 { + const f64_toint = 1.0 / math.floatEps(f64); + const u = @bitCast(u64, x); const e = (u >> 52) & 0x7FF; var y: f64 = undefined; @@ -107,9 +109,9 @@ fn floor64(x: f64) f64 { } if (u >> 63 != 0) { - y = x - math.f64_toint + math.f64_toint - x; + y = x - f64_toint + f64_toint - x; } else { - y = x + math.f64_toint - math.f64_toint - x; + y = x + f64_toint - f64_toint - x; } if (e <= 0x3FF - 1) { @@ -127,6 +129,8 @@ fn floor64(x: f64) f64 { } fn floor128(x: f128) f128 { + const f128_toint = 1.0 / math.floatEps(f128); + const u = @bitCast(u128, x); const e = (u >> 112) & 0x7FFF; var y: f128 = undefined; @@ -134,9 +138,9 @@ fn floor128(x: f128) f128 { if (e >= 0x3FFF + 112 or x == 0) return x; if (u >> 127 != 0) { - y = x - math.f128_toint + math.f128_toint - x; + y = x - f128_toint + f128_toint - x; } else { - y = x + math.f128_toint - math.f128_toint - x; + y = x + f128_toint - f128_toint - x; } if (e <= 0x3FFF - 1) { |
