zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 004872baec3fc71236ee6503a6e0885a4bae7dd0 (tree)
parent 3dc2a1f9ac572e1205cc2202e12f4d948ca67fd5
Author: kj4tmp@gmail.com <kj4tmp@gmail.com>
Date:   Wed, 28 Jan 2026 22:42:45 -0800

zig libc: acosf: fix fp exceptions

some fp exceptions are prohibited by zig test-libc (libc-test).
Promoting to f64 prevents vectorization of some floating point
divisions. The vectorization has unused lanes which contain zero. On
division the lanes containing zero are divided and trigger the INVALID
fp flags.

Diffstat:
Mlib/std/math/acos.zig | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig @@ -81,9 +81,13 @@ fn rationalApproxBinary32(z: f32) f32 { const pS2: f32 = -8.6563630030e-03; const qS1: f32 = -7.0662963390e-01; - const p = z * (pS0 + z * (pS1 + z * pS2)); - const q = 1.0 + z * qS1; - return p / q; + // f64 is used instead of f32 to avoid + // a vectorization on x86_64. The vectorization + // causes extra floating point execeptions + // that are prohibited by libc-test. + const p: f64 = @as(f64, @floatCast(z)) * (pS0 + z * (pS1 + z * pS2)); + const q: f64 = 1.0 + z * qS1; + return @floatCast(p / q); } fn acosBinary32(x: f32) f32 {