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/ceil.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/ceil.zig')
| -rw-r--r-- | lib/std/math/ceil.zig | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig index cf3adcf5b5..686be8e58d 100644 --- a/lib/std/math/ceil.zig +++ b/lib/std/math/ceil.zig @@ -62,6 +62,8 @@ fn ceil32(x: f32) f32 { } fn ceil64(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; @@ -71,9 +73,9 @@ fn ceil64(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) { @@ -91,6 +93,8 @@ fn ceil64(x: f64) f64 { } fn ceil128(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; @@ -98,9 +102,9 @@ fn ceil128(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) { |
