| author | |
| committer | |
| log | 4cad6f5372f6f17e249c24fba4d23466fa853fc0 |
| tree | 570937b9a319f0e31af630229fe507275379b590 |
| parent | 014178725744eda46db04ccfe44187ef616ceaf7 |
| signature |
The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=modfl -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```6 files changed, 9 insertions(+), 99 deletions(-)
lib/c/math.zig+9-2| ... | ... | @@ -39,6 +39,7 @@ comptime { |
| 39 | 39 | symbol(&hypotf, "hypotf"); |
| 40 | 40 | symbol(&hypotl, "hypotl"); |
| 41 | 41 | symbol(&modff, "modff"); |
| 42 | symbol(&modfl, "modfl"); | |
| 42 | 43 | symbol(&nan, "nan"); |
| 43 | 44 | symbol(&nanf, "nanf"); |
| 44 | 45 | symbol(&nanl, "nanl"); |
| ... | ... | @@ -201,11 +202,16 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 { |
| 201 | 202 | return modfGeneric(f32, x, iptr); |
| 202 | 203 | } |
| 203 | 204 | |
| 205 | fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble { | |
| 206 | return modfGeneric(c_longdouble, x, iptr); | |
| 207 | } | |
| 208 | ||
| 204 | 209 | fn testModf(comptime T: type) !void { |
| 205 | 210 | // Choose the appropriate `modf` impl to test based on type |
| 206 | 211 | const f = switch (T) { |
| 207 | f64 => modf, | |
| 208 | 212 | f32 => modff, |
| 213 | f64 => modf, | |
| 214 | c_longdouble => modfl, | |
| 209 | 215 | else => @compileError("modf not implemented for " ++ @typeName(T)), |
| 210 | 216 | }; |
| 211 | 217 | |
| ... | ... | @@ -248,8 +254,9 @@ fn testModf(comptime T: type) !void { |
| 248 | 254 | } |
| 249 | 255 | |
| 250 | 256 | test "modf" { |
| 251 | try testModf(f64); | |
| 252 | 257 | try testModf(f32); |
| 258 | try testModf(f64); | |
| 259 | try testModf(c_longdouble); | |
| 253 | 260 | } |
| 254 | 261 | |
| 255 | 262 | fn nan(_: [*:0]const c_char) callconv(.c) f64 { |
lib/libc/mingw/math/modfl.c deleted-41| ... | ... | @@ -1,41 +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 <fenv.h> | |
| 7 | #include <math.h> | |
| 8 | #include <errno.h> | |
| 9 | ||
| 10 | long double | |
| 11 | modfl (long double value, long double* iptr) | |
| 12 | { | |
| 13 | long double int_part = 0.0L; | |
| 14 | /* truncate */ | |
| 15 | #if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__)) | |
| 16 | asm volatile ("subq $8, %%rsp\n" | |
| 17 | "fnstcw 4(%%rsp)\n" | |
| 18 | "movzwl 4(%%rsp), %%eax\n" | |
| 19 | "orb $12, %%ah\n" | |
| 20 | "movw %%ax, (%%rsp)\n" | |
| 21 | "fldcw (%%rsp)\n" | |
| 22 | "frndint\n" | |
| 23 | "fldcw 4(%%rsp)\n" | |
| 24 | "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */ | |
| 25 | #elif defined(_X86_) || defined(__i386__) | |
| 26 | asm volatile ("push %%eax\n\tsubl $8, %%esp\n" | |
| 27 | "fnstcw 4(%%esp)\n" | |
| 28 | "movzwl 4(%%esp), %%eax\n" | |
| 29 | "orb $12, %%ah\n" | |
| 30 | "movw %%ax, (%%esp)\n" | |
| 31 | "fldcw (%%esp)\n" | |
| 32 | "frndint\n" | |
| 33 | "fldcw 4(%%esp)\n" | |
| 34 | "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */ | |
| 35 | #else | |
| 36 | int_part = truncl(value); | |
| 37 | #endif | |
| 38 | if (iptr) | |
| 39 | *iptr = int_part; | |
| 40 | return (isinf (value) ? 0.0L : value - int_part); | |
| 41 | } |
lib/libc/musl/src/math/modfl.c deleted-53| ... | ... | @@ -1,53 +0,0 @@ |
| 1 | #include "libm.h" | |
| 2 | ||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | |
| 4 | long double modfl(long double x, long double *iptr) | |
| 5 | { | |
| 6 | 	double d; | |
| 7 | 	long double r; | |
| 8 | ||
| 9 | 	r = modf(x, &d); | |
| 10 | 	*iptr = d; | |
| 11 | 	return r; | |
| 12 | } | |
| 13 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | |
| 14 | ||
| 15 | static const long double toint = 1/LDBL_EPSILON; | |
| 16 | ||
| 17 | long double modfl(long double x, long double *iptr) | |
| 18 | { | |
| 19 | 	union ldshape u = {x}; | |
| 20 | 	int e = (u.i.se & 0x7fff) - 0x3fff; | |
| 21 | 	int s = u.i.se >> 15; | |
| 22 | 	long double absx; | |
| 23 | 	long double y; | |
| 24 | ||
| 25 | 	/* no fractional part */ | |
| 26 | 	if (e >= LDBL_MANT_DIG-1) { | |
| 27 | 		*iptr = x; | |
| 28 | 		if (isnan(x)) | |
| 29 | 			return x; | |
| 30 | 		return s ? -0.0 : 0.0; | |
| 31 | 	} | |
| 32 | ||
| 33 | 	/* no integral part*/ | |
| 34 | 	if (e < 0) { | |
| 35 | 		*iptr = s ? -0.0 : 0.0; | |
| 36 | 		return x; | |
| 37 | 	} | |
| 38 | ||
| 39 | 	/* raises spurious inexact */ | |
| 40 | 	absx = s ? -x : x; | |
| 41 | 	y = absx + toint - toint - absx; | |
| 42 | 	if (y == 0) { | |
| 43 | 		*iptr = x; | |
| 44 | 		return s ? -0.0 : 0.0; | |
| 45 | 	} | |
| 46 | 	if (y > 0) | |
| 47 | 		y -= 1; | |
| 48 | 	if (s) | |
| 49 | 		y = -y; | |
| 50 | 	*iptr = x + y; | |
| 51 | 	return -y; | |
| 52 | } | |
| 53 | #endif |
src/libs/mingw.zig-1| ... | ... | @@ -619,7 +619,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 619 | 619 | "math" ++ path.sep_str ++ "lgamma.c", |
| 620 | 620 | "math" ++ path.sep_str ++ "lgammaf.c", |
| 621 | 621 | "math" ++ path.sep_str ++ "lgammal.c", |
| 622 | "math" ++ path.sep_str ++ "modfl.c", | |
| 623 | 622 | "math" ++ path.sep_str ++ "powi.c", |
| 624 | 623 | "math" ++ path.sep_str ++ "powif.c", |
| 625 | 624 | "math" ++ path.sep_str ++ "powil.c", |
src/libs/musl.zig-1| ... | ... | @@ -934,7 +934,6 @@ const src_files = [_][]const u8{ |
| 934 | 934 | "musl/src/math/__math_uflowf.c", |
| 935 | 935 | "musl/src/math/__math_xflow.c", |
| 936 | 936 | "musl/src/math/__math_xflowf.c", |
| 937 | "musl/src/math/modfl.c", | |
| 938 | 937 | "musl/src/math/nearbyint.c", |
| 939 | 938 | "musl/src/math/nearbyintf.c", |
| 940 | 939 | "musl/src/math/nearbyintl.c", |
src/libs/wasi_libc.zig-1| ... | ... | @@ -755,7 +755,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 755 | 755 | "musl/src/math/__math_uflowf.c", |
| 756 | 756 | "musl/src/math/__math_xflow.c", |
| 757 | 757 | "musl/src/math/__math_xflowf.c", |
| 758 | "musl/src/math/modfl.c", | |
| 759 | 758 | "musl/src/math/nearbyintl.c", |
| 760 | 759 | "musl/src/math/nextafter.c", |
| 761 | 760 | "musl/src/math/nextafterf.c", |