authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-13 11:31:15-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-13 11:31:15-08:00
logdbfe34167de6b2a3a46ee4aff8f016c5afda7ccf
treeaae7c591afd02265e8d23443089a0992f4fd311c
parent4ea99049230b5be00ca5a09d3a3fd78ecba30594
parent004872baec3fc71236ee6503a6e0885a4bae7dd0

Merge branch 'jeffective-jeff/libzigc-acosf'

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30996

7 files changed, 13 insertions(+), 94 deletions(-)

lib/c/math.zig+5
...@@ -51,6 +51,7 @@ comptime {...@@ -51,6 +51,7 @@ comptime {
51 symbol(&pow, "pow");51 symbol(&pow, "pow");
52 symbol(&pow10, "pow10");52 symbol(&pow10, "pow10");
53 symbol(&pow10f, "pow10f");53 symbol(&pow10f, "pow10f");
54 symbol(&acosf, "acosf");
54 }55 }
5556
56 if (builtin.target.isMuslLibC()) {57 if (builtin.target.isMuslLibC()) {
...@@ -84,6 +85,10 @@ fn atanl(x: c_longdouble) callconv(.c) c_longdouble {...@@ -84,6 +85,10 @@ fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
84 };85 };
85}86}
8687
88fn acosf(x: f32) callconv(.c) f32 {
89 return std.math.acos(x);
90}
91
87fn isnan(x: f64) callconv(.c) c_int {92fn isnan(x: f64) callconv(.c) c_int {
88 return if (math.isNan(x)) 1 else 0;93 return if (math.isNan(x)) 1 else 0;
89}94}
lib/libc/musl/src/math/acosf.c deleted-71
...@@ -1,71 +0,0 @@
1/* origin: FreeBSD /usr/src/lib/msun/src/e_acosf.c */
2/*
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4 */
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16#include "libm.h"
17
18static const float
19pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
20pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
21pS0 = 1.6666586697e-01,
22pS1 = -4.2743422091e-02,
23pS2 = -8.6563630030e-03,
24qS1 = -7.0662963390e-01;
25
26static float R(float z)
27{
28 float_t p, q;
29 p = z*(pS0+z*(pS1+z*pS2));
30 q = 1.0f+z*qS1;
31 return p/q;
32}
33
34float acosf(float x)
35{
36 float z,w,s,c,df;
37 uint32_t hx,ix;
38
39 GET_FLOAT_WORD(hx, x);
40 ix = hx & 0x7fffffff;
41 /* |x| >= 1 or nan */
42 if (ix >= 0x3f800000) {
43 if (ix == 0x3f800000) {
44 if (hx >> 31)
45 return 2*pio2_hi + 0x1p-120f;
46 return 0;
47 }
48 return 0/(x-x);
49 }
50 /* |x| < 0.5 */
51 if (ix < 0x3f000000) {
52 if (ix <= 0x32800000) /* |x| < 2**-26 */
53 return pio2_hi + 0x1p-120f;
54 return pio2_hi - (x - (pio2_lo-x*R(x*x)));
55 }
56 /* x < -0.5 */
57 if (hx >> 31) {
58 z = (1+x)*0.5f;
59 s = sqrtf(z);
60 w = R(z)*s-pio2_lo;
61 return 2*(pio2_hi - (s+w));
62 }
63 /* x > 0.5 */
64 z = (1-x)*0.5f;
65 s = sqrtf(z);
66 GET_FLOAT_WORD(hx,s);
67 SET_FLOAT_WORD(df,hx&0xfffff000);
68 c = (z-df*df)/(s+df);
69 w = R(z)*s+c;
70 return 2*(df+w);
71}
lib/libc/musl/src/math/i386/acosf.s deleted-16
...@@ -1,16 +0,0 @@
1.global acosf
2.type acosf,@function
3acosf:
4 flds 4(%esp)
5 fld %st(0)
6 fld1
7 fsub %st(0),%st(1)
8 fadd %st(2)
9 fmulp
10 fsqrt
11 fabs # fix sign of zero (matters in downward rounding mode)
12 fxch %st(1)
13 fpatan
14 fstps 4(%esp)
15 flds 4(%esp)
16 ret
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 {
src/libs/musl.zig-2
...@@ -798,7 +798,6 @@ const src_files = [_][]const u8{...@@ -798,7 +798,6 @@ const src_files = [_][]const u8{
798 "musl/src/math/aarch64/nearbyint.c",798 "musl/src/math/aarch64/nearbyint.c",
799 "musl/src/math/aarch64/nearbyintf.c",799 "musl/src/math/aarch64/nearbyintf.c",
800 "musl/src/math/aarch64/rintf.c",800 "musl/src/math/aarch64/rintf.c",
801 "musl/src/math/acosf.c",
802 "musl/src/math/acosh.c",801 "musl/src/math/acosh.c",
803 "musl/src/math/acoshf.c",802 "musl/src/math/acoshf.c",
804 "musl/src/math/acoshl.c",803 "musl/src/math/acoshl.c",
...@@ -852,7 +851,6 @@ const src_files = [_][]const u8{...@@ -852,7 +851,6 @@ const src_files = [_][]const u8{
852 "musl/src/math/frexp.c",851 "musl/src/math/frexp.c",
853 "musl/src/math/frexpf.c",852 "musl/src/math/frexpf.c",
854 "musl/src/math/frexpl.c",853 "musl/src/math/frexpl.c",
855 "musl/src/math/i386/acosf.s",
856 "musl/src/math/i386/acosl.s",854 "musl/src/math/i386/acosl.s",
857 "musl/src/math/i386/asinf.s",855 "musl/src/math/i386/asinf.s",
858 "musl/src/math/i386/asinl.s",856 "musl/src/math/i386/asinl.s",
src/libs/wasi_libc.zig-1
...@@ -664,7 +664,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -664,7 +664,6 @@ const libc_top_half_src_files = [_][]const u8{
664 "musl/src/locale/strtod_l.c",664 "musl/src/locale/strtod_l.c",
665 "musl/src/locale/wcscoll.c",665 "musl/src/locale/wcscoll.c",
666 "musl/src/locale/wcsxfrm.c",666 "musl/src/locale/wcsxfrm.c",
667 "musl/src/math/acosf.c",
668 "musl/src/math/acosh.c",667 "musl/src/math/acosh.c",
669 "musl/src/math/acoshf.c",668 "musl/src/math/acoshf.c",
670 "musl/src/math/acoshl.c",669 "musl/src/math/acoshl.c",
test/libc.zig+1-1
...@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.LibcContext) void {...@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.LibcContext) void {
139 cases.addLibcTestCase("regression/wcsstr-false-negative.c", true, .{});139 cases.addLibcTestCase("regression/wcsstr-false-negative.c", true, .{});
140140
141 cases.addLibcTestCase("math/acos.c", true, .{});141 cases.addLibcTestCase("math/acos.c", true, .{});
142 // cases.addLibcTestCase("math/acosf.c", true, .{});142 cases.addLibcTestCase("math/acosf.c", true, .{});
143 // cases.addLibcTestCase("math/acosh.c", true, .{});143 // cases.addLibcTestCase("math/acosh.c", true, .{});
144 cases.addLibcTestCase("math/acoshf.c", true, .{});144 cases.addLibcTestCase("math/acoshf.c", true, .{});
145 // cases.addLibcTestCase("math/acoshl.c", true, .{});145 // cases.addLibcTestCase("math/acoshl.c", true, .{});