authorgravatar for kj4tmp@gmail.comkj4tmp <kj4tmp@gmail.com> 2026-01-28 22:42:45-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-13 11:30:19-08:00
log004872baec3fc71236ee6503a6e0885a4bae7dd0
treeaae7c591afd02265e8d23443089a0992f4fd311c
parent3dc2a1f9ac572e1205cc2202e12f4d948ca67fd5

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.

1 files changed, 7 insertions(+), 3 deletions(-)

lib/std/math/acos.zig+7-3
...@@ -81,9 +81,13 @@ fn rationalApproxBinary32(z: f32) f32 {...@@ -81,9 +81,13 @@ fn rationalApproxBinary32(z: f32) f32 {
81 const pS2: f32 = -8.6563630030e-03;81 const pS2: f32 = -8.6563630030e-03;
82 const qS1: f32 = -7.0662963390e-01;82 const qS1: f32 = -7.0662963390e-01;
8383
84 const p = z * (pS0 + z * (pS1 + z * pS2));84 // f64 is used instead of f32 to avoid
85 const q = 1.0 + z * qS1;85 // a vectorization on x86_64. The vectorization
86 return p / q;86 // causes extra floating point execeptions
87 // that are prohibited by libc-test.
88 const p: f64 = @as(f64, @floatCast(z)) * (pS0 + z * (pS1 + z * pS2));
89 const q: f64 = 1.0 + z * qS1;
90 return @floatCast(p / q);
87}91}
8892
89fn acosBinary32(x: f32) f32 {93fn acosBinary32(x: f32) f32 {