authorgravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-20 17:44:23+01:00
committergravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-04-02 23:54:19+02:00
log2cbd6980e5a06ce4a2828a10b6cdb0efba827f84
tree929d229b69c5b86bf9c31f0c96ac506d3928988c
parentdb1e649575a741527ca0fd7815515c2f97924410
signaturebadge-check Signed by SSH key SHA256:aoFoShdYLdrqMichqKXSSieTKUfACUIDJHsKc4V2tQg

`libzigc/math`: Implement `finite`, `finitef`

The behaviour of `libc` `finite` functions is the same as Zig std's, so the function basically delegates to `math.isFinite` and no new tests were added. These functions are obsolete, but still part of `musl`. No results are attached in this case as `libc-test` doesn't have tests for them.

5 files changed, 10 insertions(+), 18 deletions(-)

lib/c/math.zig+10
......@@ -62,6 +62,8 @@ comptime {
6262 symbol(&exp10, "exp10");
6363 symbol(&exp10f, "exp10f");
6464 symbol(&fdim, "fdim");
65 symbol(&finite, "finite");
66 symbol(&finitef, "finitef");
6567 symbol(&frexp, "frexp");
6668 symbol(&hypot, "hypot");
6769 symbol(&modf, "modf");
......@@ -164,6 +166,14 @@ fn fdim(x: f64, y: f64) callconv(.c) f64 {
164166 return 0;
165167}
166168
169fn finite(x: f64) callconv(.c) c_int {
170 return if (math.isFinite(x)) 1 else 0;
171}
172
173fn finitef(x: f32) callconv(.c) c_int {
174 return if (math.isFinite(x)) 1 else 0;
175}
176
167177fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
168178 // libc expects `*e` to be unspecified in this case; an unspecified C value
169179 // should be a valid value of the relevant type, yet Zig's std
lib/libc/musl/src/math/finite.c deleted-7
......@@ -1,7 +0,0 @@
1#define _GNU_SOURCE
2#include <math.h>
3
4int finite(double x)
5{
6 return isfinite(x);
7}
lib/libc/musl/src/math/finitef.c deleted-7
......@@ -1,7 +0,0 @@
1#define _GNU_SOURCE
2#include <math.h>
3
4int finitef(float x)
5{
6 return isfinite(x);
7}
src/libs/musl.zig-2
......@@ -831,8 +831,6 @@ const src_files = [_][]const u8{
831831 "musl/src/math/__expo2f.c",
832832 "musl/src/math/fdimf.c",
833833 "musl/src/math/fdiml.c",
834 "musl/src/math/finite.c",
835 "musl/src/math/finitef.c",
836834 "musl/src/math/fma.c",
837835 "musl/src/math/fmaf.c",
838836 "musl/src/math/fmal.c",
src/libs/wasi_libc.zig-2
......@@ -697,8 +697,6 @@ const libc_top_half_src_files = [_][]const u8{
697697 "musl/src/math/expm1l.c",
698698 "musl/src/math/fdimf.c",
699699 "musl/src/math/fdiml.c",
700 "musl/src/math/finite.c",
701 "musl/src/math/finitef.c",
702700 "musl/src/math/fma.c",
703701 "musl/src/math/fmaf.c",
704702 "musl/src/math/ilogb.c",