diff --git a/lib/c/math.zig b/lib/c/math.zig index 497154ea04..6f86c925df 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -39,6 +39,7 @@ comptime { symbol(&hypotf, "hypotf"); symbol(&hypotl, "hypotl"); symbol(&modff, "modff"); + symbol(&modfl, "modfl"); symbol(&nan, "nan"); symbol(&nanf, "nanf"); symbol(&nanl, "nanl"); @@ -201,11 +202,16 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 { return modfGeneric(f32, x, iptr); } +fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble { + return modfGeneric(c_longdouble, x, iptr); +} + fn testModf(comptime T: type) !void { // Choose the appropriate `modf` impl to test based on type const f = switch (T) { - f64 => modf, f32 => modff, + f64 => modf, + c_longdouble => modfl, else => @compileError("modf not implemented for " ++ @typeName(T)), }; @@ -248,8 +254,9 @@ fn testModf(comptime T: type) !void { } test "modf" { - try testModf(f64); try testModf(f32); + try testModf(f64); + try testModf(c_longdouble); } fn nan(_: [*:0]const c_char) callconv(.c) f64 { diff --git a/lib/libc/mingw/math/modfl.c b/lib/libc/mingw/math/modfl.c deleted file mode 100644 index 60b9b81b92..0000000000 --- a/lib/libc/mingw/math/modfl.c +++ /dev/null @@ -1,41 +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 -#include -#include - -long double -modfl (long double value, long double* iptr) -{ - long double int_part = 0.0L; - /* truncate */ -#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__)) - asm volatile ("subq $8, %%rsp\n" - "fnstcw 4(%%rsp)\n" - "movzwl 4(%%rsp), %%eax\n" - "orb $12, %%ah\n" - "movw %%ax, (%%rsp)\n" - "fldcw (%%rsp)\n" - "frndint\n" - "fldcw 4(%%rsp)\n" - "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */ -#elif defined(_X86_) || defined(__i386__) - asm volatile ("push %%eax\n\tsubl $8, %%esp\n" - "fnstcw 4(%%esp)\n" - "movzwl 4(%%esp), %%eax\n" - "orb $12, %%ah\n" - "movw %%ax, (%%esp)\n" - "fldcw (%%esp)\n" - "frndint\n" - "fldcw 4(%%esp)\n" - "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */ -#else - int_part = truncl(value); -#endif - if (iptr) - *iptr = int_part; - return (isinf (value) ? 0.0L : value - int_part); -} diff --git a/lib/libc/musl/src/math/modfl.c b/lib/libc/musl/src/math/modfl.c deleted file mode 100644 index a47b1924f7..0000000000 --- a/lib/libc/musl/src/math/modfl.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double modfl(long double x, long double *iptr) -{ - double d; - long double r; - - r = modf(x, &d); - *iptr = d; - return r; -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double modfl(long double x, long double *iptr) -{ - union ldshape u = {x}; - int e = (u.i.se & 0x7fff) - 0x3fff; - int s = u.i.se >> 15; - long double absx; - long double y; - - /* no fractional part */ - if (e >= LDBL_MANT_DIG-1) { - *iptr = x; - if (isnan(x)) - return x; - return s ? -0.0 : 0.0; - } - - /* no integral part*/ - if (e < 0) { - *iptr = s ? -0.0 : 0.0; - return x; - } - - /* raises spurious inexact */ - absx = s ? -x : x; - y = absx + toint - toint - absx; - if (y == 0) { - *iptr = x; - return s ? -0.0 : 0.0; - } - if (y > 0) - y -= 1; - if (s) - y = -y; - *iptr = x + y; - return -y; -} -#endif diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig index 8168febe6d..312a9a1e26 100644 --- a/src/libs/mingw.zig +++ b/src/libs/mingw.zig @@ -619,7 +619,6 @@ const mingw32_generic_src = [_][]const u8{ "math" ++ path.sep_str ++ "lgamma.c", "math" ++ path.sep_str ++ "lgammaf.c", "math" ++ path.sep_str ++ "lgammal.c", - "math" ++ path.sep_str ++ "modfl.c", "math" ++ path.sep_str ++ "powi.c", "math" ++ path.sep_str ++ "powif.c", "math" ++ path.sep_str ++ "powil.c", diff --git a/src/libs/musl.zig b/src/libs/musl.zig index ee7f63bf56..9ac12e26e5 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -934,7 +934,6 @@ const src_files = [_][]const u8{ "musl/src/math/__math_uflowf.c", "musl/src/math/__math_xflow.c", "musl/src/math/__math_xflowf.c", - "musl/src/math/modfl.c", "musl/src/math/nearbyint.c", "musl/src/math/nearbyintf.c", "musl/src/math/nearbyintl.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig index 3077aad385..35640264ef 100644 --- a/src/libs/wasi_libc.zig +++ b/src/libs/wasi_libc.zig @@ -755,7 +755,6 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/math/__math_uflowf.c", "musl/src/math/__math_xflow.c", "musl/src/math/__math_xflowf.c", - "musl/src/math/modfl.c", "musl/src/math/nearbyintl.c", "musl/src/math/nextafter.c", "musl/src/math/nextafterf.c",