authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-01 20:02:06+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-01 20:02:06+01:00
log171459f678a5e1397498d3cb3d40d4cf007baaba
treed0dbfbd5101501ca5c71397379f9d15338e6e2c7
parent59073484baf89072aa02f23fe9a09662e5def100
parent379d128cba904a7599ebb191afa0873ef1a633cc

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>

11 files changed, 2 insertions(+), 157 deletions(-)

lib/libc/musl/src/math/aarch64/round.c deleted-7
...@@ -1,7 +0,0 @@
1#include <math.h>
2
3double round(double x)
4{
5 __asm__ ("frinta %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/musl/src/math/aarch64/roundf.c deleted-7
...@@ -1,7 +0,0 @@
1#include <math.h>
2
3float roundf(float x)
4{
5 __asm__ ("frinta %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/musl/src/math/powerpc64/round.c deleted-15
...@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double round(double x)
6{
7 __asm__ ("frin %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../round.c"
14
15#endif
lib/libc/musl/src/math/powerpc64/roundf.c deleted-15
...@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float roundf(float x)
6{
7 __asm__ ("frin %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../roundf.c"
14
15#endif
lib/libc/musl/src/math/round.c deleted-35
...@@ -1,35 +0,0 @@
1#include "libm.h"
2
3#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
4#define EPS DBL_EPSILON
5#elif FLT_EVAL_METHOD==2
6#define EPS LDBL_EPSILON
7#endif
8static const double_t toint = 1/EPS;
9
10double round(double x)
11{
12 union {double f; uint64_t i;} u = {x};
13 int e = u.i >> 52 & 0x7ff;
14 double_t y;
15
16 if (e >= 0x3ff+52)
17 return x;
18 if (u.i >> 63)
19 x = -x;
20 if (e < 0x3ff-1) {
21 /* raise inexact if x!=0 */
22 FORCE_EVAL(x + toint);
23 return 0*u.f;
24 }
25 y = x + toint - toint - x;
26 if (y > 0.5)
27 y = y + x - 1;
28 else if (y <= -0.5)
29 y = y + x + 1;
30 else
31 y = y + x;
32 if (u.i >> 63)
33 y = -y;
34 return y;
35}
lib/libc/musl/src/math/roundf.c deleted-36
...@@ -1,36 +0,0 @@
1#include "libm.h"
2
3#if FLT_EVAL_METHOD==0
4#define EPS FLT_EPSILON
5#elif FLT_EVAL_METHOD==1
6#define EPS DBL_EPSILON
7#elif FLT_EVAL_METHOD==2
8#define EPS LDBL_EPSILON
9#endif
10static const float_t toint = 1/EPS;
11
12float roundf(float x)
13{
14 union {float f; uint32_t i;} u = {x};
15 int e = u.i >> 23 & 0xff;
16 float_t y;
17
18 if (e >= 0x7f+23)
19 return x;
20 if (u.i >> 31)
21 x = -x;
22 if (e < 0x7f-1) {
23 FORCE_EVAL(x + toint);
24 return 0*u.f;
25 }
26 y = x + toint - toint - x;
27 if (y > 0.5f)
28 y = y + x - 1;
29 else if (y <= -0.5f)
30 y = y + x + 1;
31 else
32 y = y + x;
33 if (u.i >> 31)
34 y = -y;
35 return y;
36}
lib/libc/musl/src/math/s390x/round.c deleted-15
...@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double round(double x)
6{
7 __asm__ ("fidbra %0, 1, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../round.c"
14
15#endif
lib/libc/musl/src/math/s390x/roundf.c deleted-15
...@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float roundf(float x)
6{
7 __asm__ ("fiebra %0, 1, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../roundf.c"
14
15#endif
src/libs/musl.zig-8
...@@ -818,8 +818,6 @@ const src_files = [_][]const u8{...@@ -818,8 +818,6 @@ const src_files = [_][]const u8{
818 "musl/src/math/aarch64/nearbyintf.c",818 "musl/src/math/aarch64/nearbyintf.c",
819 "musl/src/math/aarch64/rint.c",819 "musl/src/math/aarch64/rint.c",
820 "musl/src/math/aarch64/rintf.c",820 "musl/src/math/aarch64/rintf.c",
821 "musl/src/math/aarch64/round.c",
822 "musl/src/math/aarch64/roundf.c",
823 "musl/src/math/acosf.c",821 "musl/src/math/acosf.c",
824 "musl/src/math/acosh.c",822 "musl/src/math/acosh.c",
825 "musl/src/math/acoshf.c",823 "musl/src/math/acoshf.c",
...@@ -997,8 +995,6 @@ const src_files = [_][]const u8{...@@ -997,8 +995,6 @@ const src_files = [_][]const u8{
997 "musl/src/math/powerpc64/lrintf.c",995 "musl/src/math/powerpc64/lrintf.c",
998 "musl/src/math/powerpc64/lround.c",996 "musl/src/math/powerpc64/lround.c",
999 "musl/src/math/powerpc64/lroundf.c",997 "musl/src/math/powerpc64/lroundf.c",
1000 "musl/src/math/powerpc64/round.c",
1001 "musl/src/math/powerpc64/roundf.c",
1002 "musl/src/math/powerpc/fma.c",998 "musl/src/math/powerpc/fma.c",
1003 "musl/src/math/powerpc/fmaf.c",999 "musl/src/math/powerpc/fmaf.c",
1004 "musl/src/math/powf.c",1000 "musl/src/math/powf.c",
...@@ -1021,8 +1017,6 @@ const src_files = [_][]const u8{...@@ -1021,8 +1017,6 @@ const src_files = [_][]const u8{
1021 "musl/src/math/riscv32/fmaf.c",1017 "musl/src/math/riscv32/fmaf.c",
1022 "musl/src/math/riscv64/fma.c",1018 "musl/src/math/riscv64/fma.c",
1023 "musl/src/math/riscv64/fmaf.c",1019 "musl/src/math/riscv64/fmaf.c",
1024 "musl/src/math/round.c",
1025 "musl/src/math/roundf.c",
1026 "musl/src/math/s390x/fma.c",1020 "musl/src/math/s390x/fma.c",
1027 "musl/src/math/s390x/fmaf.c",1021 "musl/src/math/s390x/fmaf.c",
1028 "musl/src/math/s390x/nearbyint.c",1022 "musl/src/math/s390x/nearbyint.c",
...@@ -1031,8 +1025,6 @@ const src_files = [_][]const u8{...@@ -1031,8 +1025,6 @@ const src_files = [_][]const u8{
1031 "musl/src/math/s390x/rint.c",1025 "musl/src/math/s390x/rint.c",
1032 "musl/src/math/s390x/rintf.c",1026 "musl/src/math/s390x/rintf.c",
1033 "musl/src/math/s390x/rintl.c",1027 "musl/src/math/s390x/rintl.c",
1034 "musl/src/math/s390x/round.c",
1035 "musl/src/math/s390x/roundf.c",
1036 "musl/src/math/scalb.c",1028 "musl/src/math/scalb.c",
1037 "musl/src/math/scalbf.c",1029 "musl/src/math/scalbf.c",
1038 "musl/src/math/scalbln.c",1030 "musl/src/math/scalbln.c",
src/libs/wasi_libc.zig-2
...@@ -808,8 +808,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -808,8 +808,6 @@ const libc_top_half_src_files = [_][]const u8{
808 "musl/src/math/remquof.c",808 "musl/src/math/remquof.c",
809 "musl/src/math/remquol.c",809 "musl/src/math/remquol.c",
810 "musl/src/math/rintl.c",810 "musl/src/math/rintl.c",
811 "musl/src/math/round.c",
812 "musl/src/math/roundf.c",
813 "musl/src/math/scalb.c",811 "musl/src/math/scalb.c",
814 "musl/src/math/scalbf.c",812 "musl/src/math/scalbf.c",
815 "musl/src/math/scalbln.c",813 "musl/src/math/scalbln.c",
test/libc.zig+2-2
...@@ -296,8 +296,8 @@ pub fn addCases(cases: *tests.LibcContext) void {...@@ -296,8 +296,8 @@ pub fn addCases(cases: *tests.LibcContext) void {
296 // cases.addLibcTestCase("math/rint.c", true, .{});296 // cases.addLibcTestCase("math/rint.c", true, .{});
297 cases.addLibcTestCase("math/rintf.c", true, .{});297 cases.addLibcTestCase("math/rintf.c", true, .{});
298 // cases.addLibcTestCase("math/rintl.c", true, .{});298 // cases.addLibcTestCase("math/rintl.c", true, .{});
299 // cases.addLibcTestCase("math/round.c", true, .{});299 cases.addLibcTestCase("math/round.c", true, .{});
300 // cases.addLibcTestCase("math/roundf.c", true, .{});300 cases.addLibcTestCase("math/roundf.c", true, .{});
301 cases.addLibcTestCase("math/roundl.c", true, .{});301 cases.addLibcTestCase("math/roundl.c", true, .{});
302 cases.addLibcTestCase("math/scalb.c", true, .{});302 cases.addLibcTestCase("math/scalb.c", true, .{});
303 cases.addLibcTestCase("math/scalbf.c", true, .{});303 cases.addLibcTestCase("math/scalbf.c", true, .{});