authorgravatar for kj4tmp@gmail.comkj4tmp <kj4tmp@gmail.com> 2026-01-31 22:55:11-08:00
committergravatar for kj4tmp@gmail.comkj4tmp <kj4tmp@gmail.com> 2026-02-01 00:09:54-08:00
log4aadb5e4a5e09d6b2018fecb364c0fabec028c9a
tree46f3fab5d3535fadb7769e3ab2b354a2b6fdde35
parent0aae9768aab8e1b534eb9a7682ad36ab4ef0487d

libzigc: cbrtf


4 files changed, 5 insertions(+), 68 deletions(-)

lib/c/math.zig+5
...@@ -40,6 +40,7 @@ comptime {...@@ -40,6 +40,7 @@ comptime {
40 @export(&atan, .{ .name = "atan", .linkage = common.linkage, .visibility = common.visibility });40 @export(&atan, .{ .name = "atan", .linkage = common.linkage, .visibility = common.visibility });
41 @export(&atanl, .{ .name = "atanl", .linkage = common.linkage, .visibility = common.visibility });41 @export(&atanl, .{ .name = "atanl", .linkage = common.linkage, .visibility = common.visibility });
42 @export(&cbrt, .{ .name = "cbrt", .linkage = common.linkage, .visibility = common.visibility });42 @export(&cbrt, .{ .name = "cbrt", .linkage = common.linkage, .visibility = common.visibility });
43 @export(&cbrtf, .{ .name = "cbrtf", .linkage = common.linkage, .visibility = common.visibility });
43 }44 }
4445
45 if (builtin.target.isMuslLibC()) {46 if (builtin.target.isMuslLibC()) {
...@@ -111,3 +112,7 @@ fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {...@@ -111,3 +112,7 @@ fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
111fn cbrt(x: f64) callconv(.c) f64 {112fn cbrt(x: f64) callconv(.c) f64 {
112 return math.cbrt(x);113 return math.cbrt(x);
113}114}
115
116fn cbrtf(x: f32) callconv(.c) f32 {
117 return math.cbrt(x);
118}
lib/libc/musl/src/math/cbrtf.c deleted-66
...@@ -1,66 +0,0 @@
1/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */
2/*
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4 * Debugged and optimized by Bruce D. Evans.
5 */
6/*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 *
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
15 */
16/* cbrtf(x)
17 * Return cube root of x
18 */
19
20#include <math.h>
21#include <stdint.h>
22
23static const unsigned
24B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
25B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
26
27float cbrtf(float x)
28{
29 double_t r,T;
30 union {float f; uint32_t i;} u = {x};
31 uint32_t hx = u.i & 0x7fffffff;
32
33 if (hx >= 0x7f800000) /* cbrt(NaN,INF) is itself */
34 return x + x;
35
36 /* rough cbrt to 5 bits */
37 if (hx < 0x00800000) { /* zero or subnormal? */
38 if (hx == 0)
39 return x; /* cbrt(+-0) is itself */
40 u.f = x*0x1p24f;
41 hx = u.i & 0x7fffffff;
42 hx = hx/3 + B2;
43 } else
44 hx = hx/3 + B1;
45 u.i &= 0x80000000;
46 u.i |= hx;
47
48 /*
49 * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In
50 * double precision so that its terms can be arranged for efficiency
51 * without causing overflow or underflow.
52 */
53 T = u.f;
54 r = T*T*T;
55 T = T*((double_t)x+x+r)/(x+r+r);
56
57 /*
58 * Second step Newton iteration to 47 bits. In double precision for
59 * efficiency and accuracy.
60 */
61 r = T*T*T;
62 T = T*((double_t)x+x+r)/(x+r+r);
63
64 /* rounding to 24 bits is perfect in round-to-nearest mode */
65 return T;
66}
src/libs/musl.zig-1
...@@ -839,7 +839,6 @@ const src_files = [_][]const u8{...@@ -839,7 +839,6 @@ const src_files = [_][]const u8{
839 "musl/src/math/atanh.c",839 "musl/src/math/atanh.c",
840 "musl/src/math/atanhf.c",840 "musl/src/math/atanhf.c",
841 "musl/src/math/atanhl.c",841 "musl/src/math/atanhl.c",
842 "musl/src/math/cbrtf.c",
843 "musl/src/math/cbrtl.c",842 "musl/src/math/cbrtl.c",
844 "musl/src/math/__cos.c",843 "musl/src/math/__cos.c",
845 "musl/src/math/__cosdf.c",844 "musl/src/math/__cosdf.c",
src/libs/wasi_libc.zig-1
...@@ -701,7 +701,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -701,7 +701,6 @@ const libc_top_half_src_files = [_][]const u8{
701 "musl/src/math/atanh.c",701 "musl/src/math/atanh.c",
702 "musl/src/math/atanhf.c",702 "musl/src/math/atanhf.c",
703 "musl/src/math/atanhl.c",703 "musl/src/math/atanhl.c",
704 "musl/src/math/cbrtf.c",
705 "musl/src/math/cbrtl.c",704 "musl/src/math/cbrtl.c",
706 "musl/src/math/__cos.c",705 "musl/src/math/__cos.c",
707 "musl/src/math/__cosdf.c",706 "musl/src/math/__cosdf.c",