mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)` with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose magnitude is below the rounding capacity of the constant. For a 64-bit mantissa (like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough, we lose a bit to rounding. For reference, the musl implementation does the same thing, using `mantissa - 1`: https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18 where `LDBL_MANT_DIG` is 64 for `long double` on x86. This commit also combines the floor and ceil implementations into one generic one.
This commit is contained in:
committed by
Andrew Kelley
parent
52e0f78706
commit
938efe4aab
+1
-2
@@ -221,7 +221,6 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/compiler_rt/aulldiv.zig
|
||||
lib/compiler_rt/aullrem.zig
|
||||
lib/compiler_rt/bswap.zig
|
||||
lib/compiler_rt/ceil.zig
|
||||
lib/compiler_rt/clear_cache.zig
|
||||
lib/compiler_rt/cmp.zig
|
||||
lib/compiler_rt/cmpdf2.zig
|
||||
@@ -312,7 +311,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/compiler_rt/floatuntisf.zig
|
||||
lib/compiler_rt/floatuntitf.zig
|
||||
lib/compiler_rt/floatuntixf.zig
|
||||
lib/compiler_rt/floor.zig
|
||||
lib/compiler_rt/floor_ceil.zig
|
||||
lib/compiler_rt/fma.zig
|
||||
lib/compiler_rt/fmax.zig
|
||||
lib/compiler_rt/fmin.zig
|
||||
|
||||
Reference in New Issue
Block a user