authorgravatar for badayvedat@gmail.combadayvedat <badayvedat@gmail.com> 2026-04-16 01:11:04+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-16 01:11:04+02:00
loga05a25e2bbcd26ce84fa16b1a75ae13b1ecd50d2
treeae3dd0530bbb26dad0facd6b7d77f665fffd437e
parentbf402649411f8ddbfab94dbab6088215d67e0e00

zig libc: export fdiml and fdimf (#31759)

Exports `fdiml` and `fdimf` in zig libc and removes from from musl and mingw libc. Contributes to: https://codeberg.org/ziglang/zig/issues/30978 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31759 Reviewed-by: Andrew Kelley <andrew@ziglang.org> Co-authored-by: badayvedat <badayvedat@gmail.com> Co-committed-by: badayvedat <badayvedat@gmail.com>

8 files changed, 22 insertions(+), 66 deletions(-)

lib/c/math.zig+20-7
...@@ -45,6 +45,7 @@ comptime {...@@ -45,6 +45,7 @@ comptime {
45 if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {45 if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
46 symbol(&atanl, "atanl");46 symbol(&atanl, "atanl");
47 symbol(&copysignl, "copysignl");47 symbol(&copysignl, "copysignl");
48 symbol(&fdiml, "fdiml");
48 symbol(&nanl, "nanl");49 symbol(&nanl, "nanl");
49 }50 }
5051
...@@ -67,6 +68,7 @@ comptime {...@@ -67,6 +68,7 @@ comptime {
67 symbol(&exp10, "exp10");68 symbol(&exp10, "exp10");
68 symbol(&exp10f, "exp10f");69 symbol(&exp10f, "exp10f");
69 symbol(&fdim, "fdim");70 symbol(&fdim, "fdim");
71 symbol(&fdimf, "fdimf");
70 symbol(&finite, "finite");72 symbol(&finite, "finite");
71 symbol(&finitef, "finitef");73 symbol(&finitef, "finitef");
72 symbol(&frexp, "frexp");74 symbol(&frexp, "frexp");
...@@ -160,19 +162,30 @@ fn exp10f(x: f32) callconv(.c) f32 {...@@ -160,19 +162,30 @@ fn exp10f(x: f32) callconv(.c) f32 {
160 return math.pow(f32, 10.0, x);162 return math.pow(f32, 10.0, x);
161}163}
162164
163fn fdim(x: f64, y: f64) callconv(.c) f64 {165fn fdimGeneric(comptime T: type, x: T, y: T) T {
164 if (math.isNan(x)) {166 if (math.isNan(x))
165 return x;167 return x;
166 }168
167 if (math.isNan(y)) {169 if (math.isNan(y))
168 return y;170 return y;
169 }171
170 if (x > y) {172 if (x > y)
171 return x - y;173 return x - y;
172 }
173 return 0;174 return 0;
174}175}
175176
177fn fdim(x: f64, y: f64) callconv(.c) f64 {
178 return fdimGeneric(f64, x, y);
179}
180
181fn fdimf(x: f32, y: f32) callconv(.c) f32 {
182 return fdimGeneric(f32, x, y);
183}
184
185fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
186 return fdimGeneric(c_longdouble, x, y);
187}
188
176fn finite(x: f64) callconv(.c) c_int {189fn finite(x: f64) callconv(.c) c_int {
177 return if (math.isFinite(x)) 1 else 0;190 return if (math.isFinite(x)) 1 else 0;
178}191}
lib/libc/mingw/math/fdiml.c deleted-24
...@@ -1,24 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <errno.h>
7#include <math.h>
8
9long double
10fdiml (long double x, long double y)
11{
12 int cx = fpclassify (x), cy = fpclassify (y);
13 long double r;
14
15 if (cx == FP_NAN || cy == FP_NAN
16 || (y < 0 && cx == FP_INFINITE && cy == FP_INFINITE))
17 return x - y; /* Take care invalid flag is raised. */
18 if (x <= y)
19 return 0.0;
20 r = x - y;
21 if (fpclassify (r) == FP_INFINITE)
22 errno = ERANGE;
23 return r;
24}
lib/libc/musl/src/math/fdimf.c deleted-10
...@@ -1,10 +0,0 @@
1#include <math.h>
2
3float fdimf(float x, float y)
4{
5 if (isnan(x))
6 return x;
7 if (isnan(y))
8 return y;
9 return x > y ? x - y : 0;
10}
lib/libc/musl/src/math/fdiml.c deleted-18
...@@ -1,18 +0,0 @@
1#include <math.h>
2#include <float.h>
3
4#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
5long double fdiml(long double x, long double y)
6{
7 return fdim(x, y);
8}
9#else
10long double fdiml(long double x, long double y)
11{
12 if (isnan(x))
13 return x;
14 if (isnan(y))
15 return y;
16 return x > y ? x - y : 0;
17}
18#endif
src/libs/mingw.zig-1
...@@ -850,7 +850,6 @@ const mingw32_x86_src = [_][]const u8{...@@ -850,7 +850,6 @@ const mingw32_x86_src = [_][]const u8{
850 "complex" ++ path.sep_str ++ "ctanl.c",850 "complex" ++ path.sep_str ++ "ctanl.c",
851 "math" ++ path.sep_str ++ "cbrtl.c",851 "math" ++ path.sep_str ++ "cbrtl.c",
852 "math" ++ path.sep_str ++ "erfl.c",852 "math" ++ path.sep_str ++ "erfl.c",
853 "math" ++ path.sep_str ++ "fdiml.c",
854 "math" ++ path.sep_str ++ "fmal.c",853 "math" ++ path.sep_str ++ "fmal.c",
855 "math" ++ path.sep_str ++ "llrintl.c",854 "math" ++ path.sep_str ++ "llrintl.c",
856 "math" ++ path.sep_str ++ "llroundl.c",855 "math" ++ path.sep_str ++ "llroundl.c",
src/libs/musl.zig-2
...@@ -823,8 +823,6 @@ const src_files = [_][]const u8{...@@ -823,8 +823,6 @@ const src_files = [_][]const u8{
823 "musl/src/math/expm1l.c",823 "musl/src/math/expm1l.c",
824 "musl/src/math/__expo2.c",824 "musl/src/math/__expo2.c",
825 "musl/src/math/__expo2f.c",825 "musl/src/math/__expo2f.c",
826 "musl/src/math/fdimf.c",
827 "musl/src/math/fdiml.c",
828 "musl/src/math/fma.c",826 "musl/src/math/fma.c",
829 "musl/src/math/fmaf.c",827 "musl/src/math/fmaf.c",
830 "musl/src/math/fmal.c",828 "musl/src/math/fmal.c",
src/libs/wasi_libc.zig-2
...@@ -692,8 +692,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -692,8 +692,6 @@ const libc_top_half_src_files = [_][]const u8{
692 "musl/src/math/expm1.c",692 "musl/src/math/expm1.c",
693 "musl/src/math/expm1f.c",693 "musl/src/math/expm1f.c",
694 "musl/src/math/expm1l.c",694 "musl/src/math/expm1l.c",
695 "musl/src/math/fdimf.c",
696 "musl/src/math/fdiml.c",
697 "musl/src/math/fma.c",695 "musl/src/math/fma.c",
698 "musl/src/math/fmaf.c",696 "musl/src/math/fmaf.c",
699 "musl/src/math/ilogb.c",697 "musl/src/math/ilogb.c",
test/libc.zig+2-2
...@@ -198,8 +198,8 @@ pub fn addCases(cases: *tests.LibcContext) void {...@@ -198,8 +198,8 @@ pub fn addCases(cases: *tests.LibcContext) void {
198 cases.addLibcTestCase("math/fabsf.c", true, .{});198 cases.addLibcTestCase("math/fabsf.c", true, .{});
199 cases.addLibcTestCase("math/fabsl.c", true, .{});199 cases.addLibcTestCase("math/fabsl.c", true, .{});
200 cases.addLibcTestCase("math/fdim.c", true, .{});200 cases.addLibcTestCase("math/fdim.c", true, .{});
201 // cases.addLibcTestCase("math/fdimf.c", true, .{});201 cases.addLibcTestCase("math/fdimf.c", true, .{});
202 // cases.addLibcTestCase("math/fdiml.c", true, .{});202 cases.addLibcTestCase("math/fdiml.c", true, .{});
203 cases.addLibcTestCase("math/fenv.c", true, .{});203 cases.addLibcTestCase("math/fenv.c", true, .{});
204 cases.addLibcTestCase("math/floor.c", true, .{});204 cases.addLibcTestCase("math/floor.c", true, .{});
205 cases.addLibcTestCase("math/floorf.c", true, .{});205 cases.addLibcTestCase("math/floorf.c", true, .{});