zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a05a25e2bbcd26ce84fa16b1a75ae13b1ecd50d2 (tree)
parent bf402649411f8ddbfab94dbab6088215d67e0e00
Author: badayvedat <badayvedat@gmail.com>
Date:   Thu, 16 Apr 2026 01:11:04 +0200

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>

Diffstat:
Mlib/c/math.zig | 27++++++++++++++++++++-------
Dlib/libc/mingw/math/fdiml.c | 24------------------------
Dlib/libc/musl/src/math/fdimf.c | 10----------
Dlib/libc/musl/src/math/fdiml.c | 18------------------
Msrc/libs/mingw.zig | 1-
Msrc/libs/musl.zig | 2--
Msrc/libs/wasi_libc.zig | 2--
Mtest/libc.zig | 4++--
8 files changed, 22 insertions(+), 66 deletions(-)

diff --git a/lib/c/math.zig b/lib/c/math.zig @@ -45,6 +45,7 @@ comptime { if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { symbol(&atanl, "atanl"); symbol(&copysignl, "copysignl"); + symbol(&fdiml, "fdiml"); symbol(&nanl, "nanl"); } @@ -67,6 +68,7 @@ comptime { symbol(&exp10, "exp10"); symbol(&exp10f, "exp10f"); symbol(&fdim, "fdim"); + symbol(&fdimf, "fdimf"); symbol(&finite, "finite"); symbol(&finitef, "finitef"); symbol(&frexp, "frexp"); @@ -160,19 +162,30 @@ fn exp10f(x: f32) callconv(.c) f32 { return math.pow(f32, 10.0, x); } -fn fdim(x: f64, y: f64) callconv(.c) f64 { - if (math.isNan(x)) { +fn fdimGeneric(comptime T: type, x: T, y: T) T { + if (math.isNan(x)) return x; - } - if (math.isNan(y)) { + + if (math.isNan(y)) return y; - } - if (x > y) { + + if (x > y) return x - y; - } return 0; } +fn fdim(x: f64, y: f64) callconv(.c) f64 { + return fdimGeneric(f64, x, y); +} + +fn fdimf(x: f32, y: f32) callconv(.c) f32 { + return fdimGeneric(f32, x, y); +} + +fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { + return fdimGeneric(c_longdouble, x, y); +} + fn finite(x: f64) callconv(.c) c_int { return if (math.isFinite(x)) 1 else 0; } diff --git a/lib/libc/mingw/math/fdiml.c b/lib/libc/mingw/math/fdiml.c @@ -1,24 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include <errno.h> -#include <math.h> - -long double -fdiml (long double x, long double y) -{ - int cx = fpclassify (x), cy = fpclassify (y); - long double r; - - if (cx == FP_NAN || cy == FP_NAN - || (y < 0 && cx == FP_INFINITE && cy == FP_INFINITE)) - return x - y; /* Take care invalid flag is raised. */ - if (x <= y) - return 0.0; - r = x - y; - if (fpclassify (r) == FP_INFINITE) - errno = ERANGE; - return r; -} diff --git a/lib/libc/musl/src/math/fdimf.c b/lib/libc/musl/src/math/fdimf.c @@ -1,10 +0,0 @@ -#include <math.h> - -float fdimf(float x, float y) -{ - if (isnan(x)) - return x; - if (isnan(y)) - return y; - return x > y ? x - y : 0; -} diff --git a/lib/libc/musl/src/math/fdiml.c b/lib/libc/musl/src/math/fdiml.c @@ -1,18 +0,0 @@ -#include <math.h> -#include <float.h> - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fdiml(long double x, long double y) -{ - return fdim(x, y); -} -#else -long double fdiml(long double x, long double y) -{ - if (isnan(x)) - return x; - if (isnan(y)) - return y; - return x > y ? x - y : 0; -} -#endif diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig @@ -850,7 +850,6 @@ const mingw32_x86_src = [_][]const u8{ "complex" ++ path.sep_str ++ "ctanl.c", "math" ++ path.sep_str ++ "cbrtl.c", "math" ++ path.sep_str ++ "erfl.c", - "math" ++ path.sep_str ++ "fdiml.c", "math" ++ path.sep_str ++ "fmal.c", "math" ++ path.sep_str ++ "llrintl.c", "math" ++ path.sep_str ++ "llroundl.c", diff --git a/src/libs/musl.zig b/src/libs/musl.zig @@ -823,8 +823,6 @@ const src_files = [_][]const u8{ "musl/src/math/expm1l.c", "musl/src/math/__expo2.c", "musl/src/math/__expo2f.c", - "musl/src/math/fdimf.c", - "musl/src/math/fdiml.c", "musl/src/math/fma.c", "musl/src/math/fmaf.c", "musl/src/math/fmal.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig @@ -692,8 +692,6 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/math/expm1.c", "musl/src/math/expm1f.c", "musl/src/math/expm1l.c", - "musl/src/math/fdimf.c", - "musl/src/math/fdiml.c", "musl/src/math/fma.c", "musl/src/math/fmaf.c", "musl/src/math/ilogb.c", diff --git a/test/libc.zig b/test/libc.zig @@ -198,8 +198,8 @@ pub fn addCases(cases: *tests.LibcContext) void { cases.addLibcTestCase("math/fabsf.c", true, .{}); cases.addLibcTestCase("math/fabsl.c", true, .{}); cases.addLibcTestCase("math/fdim.c", true, .{}); - // cases.addLibcTestCase("math/fdimf.c", true, .{}); - // cases.addLibcTestCase("math/fdiml.c", true, .{}); + cases.addLibcTestCase("math/fdimf.c", true, .{}); + cases.addLibcTestCase("math/fdiml.c", true, .{}); cases.addLibcTestCase("math/fenv.c", true, .{}); cases.addLibcTestCase("math/floor.c", true, .{}); cases.addLibcTestCase("math/floorf.c", true, .{});