mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
libzigc: Implement modfl
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 ```
This commit is contained in:
+9
-2
@@ -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 {
|
||||
|
||||
Vendored
-41
@@ -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 <fenv.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
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);
|
||||
}
|
||||
Vendored
-53
@@ -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
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user