zig

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

commit 171459f678a5e1397498d3cb3d40d4cf007baaba (tree)
parent 59073484baf89072aa02f23fe9a09662e5def100
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun,  1 Feb 2026 20:02:06 +0100

Merge pull request 'libzigc: round, roundf' (#31075) from jeffective/zig:jeff/libzigc-round into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31075
Reviewed-by: Andrew Kelley <andrew@ziglang.org>

Diffstat:
Dlib/libc/musl/src/math/aarch64/round.c | 7-------
Dlib/libc/musl/src/math/aarch64/roundf.c | 7-------
Dlib/libc/musl/src/math/powerpc64/round.c | 15---------------
Dlib/libc/musl/src/math/powerpc64/roundf.c | 15---------------
Dlib/libc/musl/src/math/round.c | 35-----------------------------------
Dlib/libc/musl/src/math/roundf.c | 36------------------------------------
Dlib/libc/musl/src/math/s390x/round.c | 15---------------
Dlib/libc/musl/src/math/s390x/roundf.c | 15---------------
Msrc/libs/musl.zig | 8--------
Msrc/libs/wasi_libc.zig | 2--
Mtest/libc.zig | 4++--
11 files changed, 2 insertions(+), 157 deletions(-)

diff --git a/lib/libc/musl/src/math/aarch64/round.c b/lib/libc/musl/src/math/aarch64/round.c @@ -1,7 +0,0 @@ -#include <math.h> - -double round(double x) -{ - __asm__ ("frinta %d0, %d1" : "=w"(x) : "w"(x)); - return x; -} diff --git a/lib/libc/musl/src/math/aarch64/roundf.c b/lib/libc/musl/src/math/aarch64/roundf.c @@ -1,7 +0,0 @@ -#include <math.h> - -float roundf(float x) -{ - __asm__ ("frinta %s0, %s1" : "=w"(x) : "w"(x)); - return x; -} diff --git a/lib/libc/musl/src/math/powerpc64/round.c b/lib/libc/musl/src/math/powerpc64/round.c @@ -1,15 +0,0 @@ -#include <math.h> - -#ifdef _ARCH_PWR5X - -double round(double x) -{ - __asm__ ("frin %0, %1" : "=d"(x) : "d"(x)); - return x; -} - -#else - -#include "../round.c" - -#endif diff --git a/lib/libc/musl/src/math/powerpc64/roundf.c b/lib/libc/musl/src/math/powerpc64/roundf.c @@ -1,15 +0,0 @@ -#include <math.h> - -#ifdef _ARCH_PWR5X - -float roundf(float x) -{ - __asm__ ("frin %0, %1" : "=f"(x) : "f"(x)); - return x; -} - -#else - -#include "../roundf.c" - -#endif diff --git a/lib/libc/musl/src/math/round.c b/lib/libc/musl/src/math/round.c @@ -1,35 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const double_t toint = 1/EPS; - -double round(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i >> 52 & 0x7ff; - double_t y; - - if (e >= 0x3ff+52) - return x; - if (u.i >> 63) - x = -x; - if (e < 0x3ff-1) { - /* raise inexact if x!=0 */ - FORCE_EVAL(x + toint); - return 0*u.f; - } - y = x + toint - toint - x; - if (y > 0.5) - y = y + x - 1; - else if (y <= -0.5) - y = y + x + 1; - else - y = y + x; - if (u.i >> 63) - y = -y; - return y; -} diff --git a/lib/libc/musl/src/math/roundf.c b/lib/libc/musl/src/math/roundf.c @@ -1,36 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 -#define EPS FLT_EPSILON -#elif FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const float_t toint = 1/EPS; - -float roundf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = u.i >> 23 & 0xff; - float_t y; - - if (e >= 0x7f+23) - return x; - if (u.i >> 31) - x = -x; - if (e < 0x7f-1) { - FORCE_EVAL(x + toint); - return 0*u.f; - } - y = x + toint - toint - x; - if (y > 0.5f) - y = y + x - 1; - else if (y <= -0.5f) - y = y + x + 1; - else - y = y + x; - if (u.i >> 31) - y = -y; - return y; -} diff --git a/lib/libc/musl/src/math/s390x/round.c b/lib/libc/musl/src/math/s390x/round.c @@ -1,15 +0,0 @@ -#include <math.h> - -#if defined(__HTM__) || __ARCH__ >= 9 - -double round(double x) -{ - __asm__ ("fidbra %0, 1, %1, 4" : "=f"(x) : "f"(x)); - return x; -} - -#else - -#include "../round.c" - -#endif diff --git a/lib/libc/musl/src/math/s390x/roundf.c b/lib/libc/musl/src/math/s390x/roundf.c @@ -1,15 +0,0 @@ -#include <math.h> - -#if defined(__HTM__) || __ARCH__ >= 9 - -float roundf(float x) -{ - __asm__ ("fiebra %0, 1, %1, 4" : "=f"(x) : "f"(x)); - return x; -} - -#else - -#include "../roundf.c" - -#endif diff --git a/src/libs/musl.zig b/src/libs/musl.zig @@ -818,8 +818,6 @@ const src_files = [_][]const u8{ "musl/src/math/aarch64/nearbyintf.c", "musl/src/math/aarch64/rint.c", "musl/src/math/aarch64/rintf.c", - "musl/src/math/aarch64/round.c", - "musl/src/math/aarch64/roundf.c", "musl/src/math/acosf.c", "musl/src/math/acosh.c", "musl/src/math/acoshf.c", @@ -997,8 +995,6 @@ const src_files = [_][]const u8{ "musl/src/math/powerpc64/lrintf.c", "musl/src/math/powerpc64/lround.c", "musl/src/math/powerpc64/lroundf.c", - "musl/src/math/powerpc64/round.c", - "musl/src/math/powerpc64/roundf.c", "musl/src/math/powerpc/fma.c", "musl/src/math/powerpc/fmaf.c", "musl/src/math/powf.c", @@ -1021,8 +1017,6 @@ const src_files = [_][]const u8{ "musl/src/math/riscv32/fmaf.c", "musl/src/math/riscv64/fma.c", "musl/src/math/riscv64/fmaf.c", - "musl/src/math/round.c", - "musl/src/math/roundf.c", "musl/src/math/s390x/fma.c", "musl/src/math/s390x/fmaf.c", "musl/src/math/s390x/nearbyint.c", @@ -1031,8 +1025,6 @@ const src_files = [_][]const u8{ "musl/src/math/s390x/rint.c", "musl/src/math/s390x/rintf.c", "musl/src/math/s390x/rintl.c", - "musl/src/math/s390x/round.c", - "musl/src/math/s390x/roundf.c", "musl/src/math/scalb.c", "musl/src/math/scalbf.c", "musl/src/math/scalbln.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig @@ -808,8 +808,6 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/math/remquof.c", "musl/src/math/remquol.c", "musl/src/math/rintl.c", - "musl/src/math/round.c", - "musl/src/math/roundf.c", "musl/src/math/scalb.c", "musl/src/math/scalbf.c", "musl/src/math/scalbln.c", diff --git a/test/libc.zig b/test/libc.zig @@ -296,8 +296,8 @@ pub fn addCases(cases: *tests.LibcContext) void { // cases.addLibcTestCase("math/rint.c", true, .{}); cases.addLibcTestCase("math/rintf.c", true, .{}); // cases.addLibcTestCase("math/rintl.c", true, .{}); - // cases.addLibcTestCase("math/round.c", true, .{}); - // cases.addLibcTestCase("math/roundf.c", true, .{}); + cases.addLibcTestCase("math/round.c", true, .{}); + cases.addLibcTestCase("math/roundf.c", true, .{}); cases.addLibcTestCase("math/roundl.c", true, .{}); cases.addLibcTestCase("math/scalb.c", true, .{}); cases.addLibcTestCase("math/scalbf.c", true, .{});