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 {...@@ -62,6 +62,8 @@ comptime {
62 symbol(&exp10, "exp10");62 symbol(&exp10, "exp10");
63 symbol(&exp10f, "exp10f");63 symbol(&exp10f, "exp10f");
64 symbol(&fdim, "fdim");64 symbol(&fdim, "fdim");
65 symbol(&finite, "finite");
66 symbol(&finitef, "finitef");
65 symbol(&frexp, "frexp");67 symbol(&frexp, "frexp");
66 symbol(&hypot, "hypot");68 symbol(&hypot, "hypot");
67 symbol(&modf, "modf");69 symbol(&modf, "modf");
...@@ -164,6 +166,14 @@ fn fdim(x: f64, y: f64) callconv(.c) f64 {...@@ -164,6 +166,14 @@ fn fdim(x: f64, y: f64) callconv(.c) f64 {
164 return 0;166 return 0;
165}167}
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
167fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {177fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
168 // libc expects `*e` to be unspecified in this case; an unspecified C value178 // libc expects `*e` to be unspecified in this case; an unspecified C value
169 // should be a valid value of the relevant type, yet Zig's std179 // 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{...@@ -831,8 +831,6 @@ const src_files = [_][]const u8{
831 "musl/src/math/__expo2f.c",831 "musl/src/math/__expo2f.c",
832 "musl/src/math/fdimf.c",832 "musl/src/math/fdimf.c",
833 "musl/src/math/fdiml.c",833 "musl/src/math/fdiml.c",
834 "musl/src/math/finite.c",
835 "musl/src/math/finitef.c",
836 "musl/src/math/fma.c",834 "musl/src/math/fma.c",
837 "musl/src/math/fmaf.c",835 "musl/src/math/fmaf.c",
838 "musl/src/math/fmal.c",836 "musl/src/math/fmal.c",
src/libs/wasi_libc.zig-2
...@@ -697,8 +697,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -697,8 +697,6 @@ const libc_top_half_src_files = [_][]const u8{
697 "musl/src/math/expm1l.c",697 "musl/src/math/expm1l.c",
698 "musl/src/math/fdimf.c",698 "musl/src/math/fdimf.c",
699 "musl/src/math/fdiml.c",699 "musl/src/math/fdiml.c",
700 "musl/src/math/finite.c",
701 "musl/src/math/finitef.c",
702 "musl/src/math/fma.c",700 "musl/src/math/fma.c",
703 "musl/src/math/fmaf.c",701 "musl/src/math/fmaf.c",
704 "musl/src/math/ilogb.c",702 "musl/src/math/ilogb.c",