From 004872baec3fc71236ee6503a6e0885a4bae7dd0 Mon Sep 17 00:00:00 2001 From: "kj4tmp@gmail.com" Date: Wed, 28 Jan 2026 22:42:45 -0800 Subject: [PATCH] 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. --- lib/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 index dae3f70c82dfa1839e6112ba7135e32e9c65ef1f..b163551d0aae2c90730855a4efbfbf4d93571969 100644 --- 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 { -- 2.54.0