authorgravatar for kj4tmp@gmail.comkj4tmp <kj4tmp@gmail.com> 2026-01-25 00:00:41-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-13 11:30:14-08:00
log3dc2a1f9ac572e1205cc2202e12f4d948ca67fd5
treebb9bf1add91a7ea0ca69b193b79d907f4650d24a
parent4ea99049230b5be00ca5a09d3a3fd78ecba30594

zig libc: acosf


6 files changed, 6 insertions(+), 91 deletions(-)

lib/c/math.zig+5
......@@ -51,6 +51,7 @@ comptime {
5151 symbol(&pow, "pow");
5252 symbol(&pow10, "pow10");
5353 symbol(&pow10f, "pow10f");
54 symbol(&acosf, "acosf");
5455 }
5556
5657 if (builtin.target.isMuslLibC()) {
......@@ -84,6 +85,10 @@ fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
8485 };
8586}
8687
88fn acosf(x: f32) callconv(.c) f32 {
89 return std.math.acos(x);
90}
91
8792fn isnan(x: f64) callconv(.c) c_int {
8893 return if (math.isNan(x)) 1 else 0;
8994}
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
src/libs/musl.zig-2
......@@ -798,7 +798,6 @@ const src_files = [_][]const u8{
798798 "musl/src/math/aarch64/nearbyint.c",
799799 "musl/src/math/aarch64/nearbyintf.c",
800800 "musl/src/math/aarch64/rintf.c",
801 "musl/src/math/acosf.c",
802801 "musl/src/math/acosh.c",
803802 "musl/src/math/acoshf.c",
804803 "musl/src/math/acoshl.c",
......@@ -852,7 +851,6 @@ const src_files = [_][]const u8{
852851 "musl/src/math/frexp.c",
853852 "musl/src/math/frexpf.c",
854853 "musl/src/math/frexpl.c",
855 "musl/src/math/i386/acosf.s",
856854 "musl/src/math/i386/acosl.s",
857855 "musl/src/math/i386/asinf.s",
858856 "musl/src/math/i386/asinl.s",
src/libs/wasi_libc.zig-1
......@@ -664,7 +664,6 @@ const libc_top_half_src_files = [_][]const u8{
664664 "musl/src/locale/strtod_l.c",
665665 "musl/src/locale/wcscoll.c",
666666 "musl/src/locale/wcsxfrm.c",
667 "musl/src/math/acosf.c",
668667 "musl/src/math/acosh.c",
669668 "musl/src/math/acoshf.c",
670669 "musl/src/math/acoshl.c",
test/libc.zig+1-1
......@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.LibcContext) void {
139139 cases.addLibcTestCase("regression/wcsstr-false-negative.c", true, .{});
140140
141141 cases.addLibcTestCase("math/acos.c", true, .{});
142 // cases.addLibcTestCase("math/acosf.c", true, .{});
142 cases.addLibcTestCase("math/acosf.c", true, .{});
143143 // cases.addLibcTestCase("math/acosh.c", true, .{});
144144 cases.addLibcTestCase("math/acoshf.c", true, .{});
145145 // cases.addLibcTestCase("math/acoshl.c", true, .{});