authorgravatar for pivoc@protonmail.comPivok <pivoc@protonmail.com> 2026-06-07 23:08:14+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-07 23:08:14+02:00
log20b3aa3bcd55ad8f3f545f5ab0f0c2ac7122e2a2
treea13d5935691f8877abec5b283da082f3f043ddf0
parent23f46bcd4d1d6cca5a25ed9e7b1222b1283de7af

libzigc: lround lroundf lroundl (#35600)

Implements lround, lroundf and lroundl for libzigc See #30978 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35600

12 files changed, 15 insertions(+), 118 deletions(-)

lib/c/math.zig+15
......@@ -37,6 +37,7 @@ comptime {
3737 symbol(&hypotf, "hypotf");
3838 symbol(&hypotl, "hypotl");
3939 symbol(&lrintl, "lrintl");
40 symbol(&lroundl, "lroundl");
4041 symbol(&modfl, "modfl");
4142 symbol(&rintl, "rintl");
4243 }
......@@ -76,6 +77,8 @@ comptime {
7677 symbol(&log1pf, "log1pf");
7778 symbol(&lrint, "lrint");
7879 symbol(&lrintf, "lrintf");
80 symbol(&lround, "lround");
81 symbol(&lroundf, "lroundf");
7982 symbol(&modf, "modf");
8083 symbol(&nan, "nan");
8184 symbol(&nanf, "nanf");
......@@ -278,6 +281,18 @@ fn lrintl(x: c_longdouble) callconv(.c) c_long {
278281 return @trunc(rintl(x));
279282}
280283
284fn lround(x: f64) callconv(.c) c_long {
285 return @round(x);
286}
287
288fn lroundf(x: f32) callconv(.c) c_long {
289 return @round(x);
290}
291
292fn lroundl(x: c_longdouble) callconv(.c) c_long {
293 return @round(x);
294}
295
281296fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
282297 if (math.isNegativeInf(x)) {
283298 iptr.* = -math.inf(T);
lib/libc/mingw/math/lroundl.c deleted-37
......@@ -1,37 +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 <math.h>
7#include <limits.h>
8#include <errno.h>
9
10long
11lroundl (long double x)
12{
13 long double res;
14
15 if (x >= 0.0L)
16 {
17 res = ceill (x);
18 if (res - x > 0.5L)
19 res -= 1.0;
20 }
21 else
22 {
23 res = ceill (-x);
24 if (res + x > 0.5L)
25 res -= 1.0L;
26 res = -res;
27 }
28 if (!isfinite (res)
29 || res > (long double)LONG_MAX
30 || res < (long double)LONG_MIN)
31 {
32 errno = ERANGE;
33 /* Undefined behaviour, so we could return anything. */
34 /* return res > 0.0L ? LONG_MAX : LONG_MIN; */
35 }
36 return (long) res;
37}
lib/libc/musl/src/math/aarch64/lround.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lround(double x)
4{
5 long n;
6 __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/musl/src/math/aarch64/lroundf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lroundf(float x)
4{
5 long n;
6 __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
7 return n;
8}
lib/libc/musl/src/math/lround.c deleted-6
......@@ -1,6 +0,0 @@
1#include <math.h>
2
3long lround(double x)
4{
5 return round(x);
6}
lib/libc/musl/src/math/lroundf.c deleted-6
......@@ -1,6 +0,0 @@
1#include <math.h>
2
3long lroundf(float x)
4{
5 return roundf(x);
6}
lib/libc/musl/src/math/lroundl.c deleted-6
......@@ -1,6 +0,0 @@
1#include <math.h>
2
3long lroundl(long double x)
4{
5 return roundl(x);
6}
lib/libc/musl/src/math/powerpc64/lround.c deleted-18
......@@ -1,18 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5long lround(double x)
6{
7 long n;
8 __asm__ (
9 "xsrdpi %1, %1\n"
10 "fctid %0, %1\n" : "=d"(n), "+d"(x));
11 return n;
12}
13
14#else
15
16#include "../lround.c"
17
18#endif
lib/libc/musl/src/math/powerpc64/lroundf.c deleted-18
......@@ -1,18 +0,0 @@
1#include <math.h>
2
3#ifdef __VSX__
4
5long lroundf(float x)
6{
7 long n;
8 __asm__ (
9 "xsrdpi %1, %1\n"
10 "fctid %0, %1\n" : "=d"(n), "+f"(x));
11 return n;
12}
13
14#else
15
16#include "../lroundf.c"
17
18#endif
src/libs/mingw.zig-1
......@@ -853,7 +853,6 @@ const mingw32_x86_src = [_][]const u8{
853853 "math" ++ path.sep_str ++ "fmal.c",
854854 "math" ++ path.sep_str ++ "llrintl.c",
855855 "math" ++ path.sep_str ++ "llroundl.c",
856 "math" ++ path.sep_str ++ "lroundl.c",
857856 "math" ++ path.sep_str ++ "tgammal.c",
858857 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S",
859858 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c",
src/libs/musl.zig-7
......@@ -784,8 +784,6 @@ const src_files = [_][]const u8{
784784 "musl/src/math/aarch64/llrintf.c",
785785 "musl/src/math/aarch64/llround.c",
786786 "musl/src/math/aarch64/llroundf.c",
787 "musl/src/math/aarch64/lround.c",
788 "musl/src/math/aarch64/lroundf.c",
789787 "musl/src/math/aarch64/nearbyint.c",
790788 "musl/src/math/aarch64/nearbyintf.c",
791789 "musl/src/math/acosh.c",
......@@ -891,9 +889,6 @@ const src_files = [_][]const u8{
891889 "musl/src/math/logbf.c",
892890 "musl/src/math/logbl.c",
893891 "musl/src/math/logl.c",
894 "musl/src/math/lround.c",
895 "musl/src/math/lroundf.c",
896 "musl/src/math/lroundl.c",
897892 "musl/src/math/__math_divzero.c",
898893 "musl/src/math/__math_divzerof.c",
899894 "musl/src/math/__math_invalid.c",
......@@ -919,8 +914,6 @@ const src_files = [_][]const u8{
919914 "musl/src/math/pow_data.c",
920915 "musl/src/math/powerpc64/fma.c",
921916 "musl/src/math/powerpc64/fmaf.c",
922 "musl/src/math/powerpc64/lround.c",
923 "musl/src/math/powerpc64/lroundf.c",
924917 "musl/src/math/powerpc/fma.c",
925918 "musl/src/math/powerpc/fmaf.c",
926919 "musl/src/math/powf.c",
src/libs/wasi_libc.zig-3
......@@ -725,9 +725,6 @@ const libc_top_half_src_files = [_][]const u8{
725725 "musl/src/math/logbf.c",
726726 "musl/src/math/logbl.c",
727727 "musl/src/math/logl.c",
728 "musl/src/math/lround.c",
729 "musl/src/math/lroundf.c",
730 "musl/src/math/lroundl.c",
731728 "musl/src/math/__math_divzero.c",
732729 "musl/src/math/__math_divzerof.c",
733730 "musl/src/math/__math_invalid.c",