| author | |
| committer | |
| log | a05a25e2bbcd26ce84fa16b1a75ae13b1ecd50d2 |
| tree | ae3dd0530bbb26dad0facd6b7d77f665fffd437e |
| parent | bf402649411f8ddbfab94dbab6088215d67e0e00 |
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 | 45 | if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 46 | 46 | symbol(&atanl, "atanl"); |
| 47 | 47 | symbol(&copysignl, "copysignl"); |
| 48 | symbol(&fdiml, "fdiml"); | |
| 48 | 49 | symbol(&nanl, "nanl"); |
| 49 | 50 | } |
| 50 | 51 | |
| ... | ... | @@ -67,6 +68,7 @@ comptime { |
| 67 | 68 | symbol(&exp10, "exp10"); |
| 68 | 69 | symbol(&exp10f, "exp10f"); |
| 69 | 70 | symbol(&fdim, "fdim"); |
| 71 | symbol(&fdimf, "fdimf"); | |
| 70 | 72 | symbol(&finite, "finite"); |
| 71 | 73 | symbol(&finitef, "finitef"); |
| 72 | 74 | symbol(&frexp, "frexp"); |
| ... | ... | @@ -160,19 +162,30 @@ fn exp10f(x: f32) callconv(.c) f32 { |
| 160 | 162 | return math.pow(f32, 10.0, x); |
| 161 | 163 | } |
| 162 | 164 | |
| 163 | fn fdim(x: f64, y: f64) callconv(.c) f64 { | |
| 164 | if (math.isNan(x)) { | |
| 165 | fn fdimGeneric(comptime T: type, x: T, y: T) T { | |
| 166 | if (math.isNan(x)) | |
| 165 | 167 | return x; |
| 166 | } | |
| 167 | if (math.isNan(y)) { | |
| 168 | ||
| 169 | if (math.isNan(y)) | |
| 168 | 170 | return y; |
| 169 | } | |
| 170 | if (x > y) { | |
| 171 | ||
| 172 | if (x > y) | |
| 171 | 173 | return x - y; |
| 172 | } | |
| 173 | 174 | return 0; |
| 174 | 175 | } |
| 175 | 176 | |
| 177 | fn fdim(x: f64, y: f64) callconv(.c) f64 { | |
| 178 | return fdimGeneric(f64, x, y); | |
| 179 | } | |
| 180 | ||
| 181 | fn fdimf(x: f32, y: f32) callconv(.c) f32 { | |
| 182 | return fdimGeneric(f32, x, y); | |
| 183 | } | |
| 184 | ||
| 185 | fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { | |
| 186 | return fdimGeneric(c_longdouble, x, y); | |
| 187 | } | |
| 188 | ||
| 176 | 189 | fn finite(x: f64) callconv(.c) c_int { |
| 177 | 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 | ||
| 9 | long double | |
| 10 | fdiml (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 | ||
| 3 | float 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 | |
| 5 | long double fdiml(long double x, long double y) | |
| 6 | { | |
| 7 | 	return fdim(x, y); | |
| 8 | } | |
| 9 | #else | |
| 10 | long 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 | 850 | "complex" ++ path.sep_str ++ "ctanl.c", |
| 851 | 851 | "math" ++ path.sep_str ++ "cbrtl.c", |
| 852 | 852 | "math" ++ path.sep_str ++ "erfl.c", |
| 853 | "math" ++ path.sep_str ++ "fdiml.c", | |
| 854 | 853 | "math" ++ path.sep_str ++ "fmal.c", |
| 855 | 854 | "math" ++ path.sep_str ++ "llrintl.c", |
| 856 | 855 | "math" ++ path.sep_str ++ "llroundl.c", |
src/libs/musl.zig-2| ... | ... | @@ -823,8 +823,6 @@ const src_files = [_][]const u8{ |
| 823 | 823 | "musl/src/math/expm1l.c", |
| 824 | 824 | "musl/src/math/__expo2.c", |
| 825 | 825 | "musl/src/math/__expo2f.c", |
| 826 | "musl/src/math/fdimf.c", | |
| 827 | "musl/src/math/fdiml.c", | |
| 828 | 826 | "musl/src/math/fma.c", |
| 829 | 827 | "musl/src/math/fmaf.c", |
| 830 | 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 | 692 | "musl/src/math/expm1.c", |
| 693 | 693 | "musl/src/math/expm1f.c", |
| 694 | 694 | "musl/src/math/expm1l.c", |
| 695 | "musl/src/math/fdimf.c", | |
| 696 | "musl/src/math/fdiml.c", | |
| 697 | 695 | "musl/src/math/fma.c", |
| 698 | 696 | "musl/src/math/fmaf.c", |
| 699 | 697 | "musl/src/math/ilogb.c", |
test/libc.zig+2-2| ... | ... | @@ -198,8 +198,8 @@ pub fn addCases(cases: *tests.LibcContext) void { |
| 198 | 198 | cases.addLibcTestCase("math/fabsf.c", true, .{}); |
| 199 | 199 | cases.addLibcTestCase("math/fabsl.c", true, .{}); |
| 200 | 200 | cases.addLibcTestCase("math/fdim.c", true, .{}); |
| 201 | // cases.addLibcTestCase("math/fdimf.c", true, .{}); | |
| 202 | // cases.addLibcTestCase("math/fdiml.c", true, .{}); | |
| 201 | cases.addLibcTestCase("math/fdimf.c", true, .{}); | |
| 202 | cases.addLibcTestCase("math/fdiml.c", true, .{}); | |
| 203 | 203 | cases.addLibcTestCase("math/fenv.c", true, .{}); |
| 204 | 204 | cases.addLibcTestCase("math/floor.c", true, .{}); |
| 205 | 205 | cases.addLibcTestCase("math/floorf.c", true, .{}); |