authorgravatar for badayvedat@gmail.combadayvedat <badayvedat@gmail.com> 2026-03-14 23:08:21+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-02 14:50:19+02:00
log6cdd576d4176c2581f796c2066ca0f92bda03c9e
treeac7bdf96f5fdb765ef438d8a92bee315f34975c7
parent28ae5d4158b084d17e55e73aec4c37e22885bd78

libzigc: fdim


5 files changed, 15 insertions(+), 13 deletions(-)

lib/c/math.zig+14
......@@ -59,6 +59,7 @@ comptime {
5959 symbol(&cosh, "cosh");
6060 symbol(&exp10, "exp10");
6161 symbol(&exp10f, "exp10f");
62 symbol(&fdim, "fdim");
6263 symbol(&hypot, "hypot");
6364 symbol(&modf, "modf");
6465 symbol(&pow, "pow");
......@@ -147,6 +148,19 @@ fn exp10f(x: f32) callconv(.c) f32 {
147148 return math.pow(f32, 10.0, x);
148149}
149150
151fn fdim(x: f64, y: f64) callconv(.c) f64 {
152 if (math.isNan(x)) {
153 return x;
154 }
155 if (math.isNan(y)) {
156 return y;
157 }
158 if (x > y) {
159 return x - y;
160 }
161 return 0;
162}
163
150164fn hypot(x: f64, y: f64) callconv(.c) f64 {
151165 return math.hypot(x, y);
152166}
lib/libc/musl/src/math/fdim.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3double fdim(double x, double y)
4{
5 if (isnan(x))
6 return x;
7 if (isnan(y))
8 return y;
9 return x > y ? x - y : 0;
10}
src/libs/musl.zig-1
......@@ -830,7 +830,6 @@ const src_files = [_][]const u8{
830830 "musl/src/math/expm1l.c",
831831 "musl/src/math/__expo2.c",
832832 "musl/src/math/__expo2f.c",
833 "musl/src/math/fdim.c",
834833 "musl/src/math/fdimf.c",
835834 "musl/src/math/fdiml.c",
836835 "musl/src/math/finite.c",
src/libs/wasi_libc.zig-1
......@@ -695,7 +695,6 @@ const libc_top_half_src_files = [_][]const u8{
695695 "musl/src/math/expm1.c",
696696 "musl/src/math/expm1f.c",
697697 "musl/src/math/expm1l.c",
698 "musl/src/math/fdim.c",
699698 "musl/src/math/fdimf.c",
700699 "musl/src/math/fdiml.c",
701700 "musl/src/math/finite.c",
test/libc.zig+1-1
......@@ -197,7 +197,7 @@ pub fn addCases(cases: *tests.LibcContext) void {
197197 cases.addLibcTestCase("math/fabs.c", true, .{});
198198 cases.addLibcTestCase("math/fabsf.c", true, .{});
199199 cases.addLibcTestCase("math/fabsl.c", true, .{});
200 // cases.addLibcTestCase("math/fdim.c", true, .{});
200 cases.addLibcTestCase("math/fdim.c", true, .{});
201201 // cases.addLibcTestCase("math/fdimf.c", true, .{});
202202 // cases.addLibcTestCase("math/fdiml.c", true, .{});
203203 cases.addLibcTestCase("math/fenv.c", true, .{});