commit 20b3aa3bcd55ad8f3f545f5ab0f0c2ac7122e2a2 (tree)
parent 23f46bcd4d1d6cca5a25ed9e7b1222b1283de7af
Author: Pivok <pivoc@protonmail.com>
Date: Sun, 7 Jun 2026 23:08:14 +0200
libzigc: lround lroundf lroundl (#35600)
Implements lround, lroundf and lroundl for libzigc
See #30978
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35600
Diffstat:
12 files changed, 15 insertions(+), 118 deletions(-)
diff --git a/lib/c/math.zig b/lib/c/math.zig
@@ -37,6 +37,7 @@ comptime {
symbol(&hypotf, "hypotf");
symbol(&hypotl, "hypotl");
symbol(&lrintl, "lrintl");
+ symbol(&lroundl, "lroundl");
symbol(&modfl, "modfl");
symbol(&rintl, "rintl");
}
@@ -76,6 +77,8 @@ comptime {
symbol(&log1pf, "log1pf");
symbol(&lrint, "lrint");
symbol(&lrintf, "lrintf");
+ symbol(&lround, "lround");
+ symbol(&lroundf, "lroundf");
symbol(&modf, "modf");
symbol(&nan, "nan");
symbol(&nanf, "nanf");
@@ -278,6 +281,18 @@ fn lrintl(x: c_longdouble) callconv(.c) c_long {
return @trunc(rintl(x));
}
+fn lround(x: f64) callconv(.c) c_long {
+ return @round(x);
+}
+
+fn lroundf(x: f32) callconv(.c) c_long {
+ return @round(x);
+}
+
+fn lroundl(x: c_longdouble) callconv(.c) c_long {
+ return @round(x);
+}
+
fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
if (math.isNegativeInf(x)) {
iptr.* = -math.inf(T);
diff --git a/lib/libc/mingw/math/lroundl.c b/lib/libc/mingw/math/lroundl.c
@@ -1,37 +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 <math.h>
-#include <limits.h>
-#include <errno.h>
-
-long
-lroundl (long double x)
-{
- long double res;
-
- if (x >= 0.0L)
- {
- res = ceill (x);
- if (res - x > 0.5L)
- res -= 1.0;
- }
- else
- {
- res = ceill (-x);
- if (res + x > 0.5L)
- res -= 1.0L;
- res = -res;
- }
- if (!isfinite (res)
- || res > (long double)LONG_MAX
- || res < (long double)LONG_MIN)
- {
- errno = ERANGE;
- /* Undefined behaviour, so we could return anything. */
- /* return res > 0.0L ? LONG_MAX : LONG_MIN; */
- }
- return (long) res;
-}
diff --git a/lib/libc/musl/src/math/aarch64/lround.c b/lib/libc/musl/src/math/aarch64/lround.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lround(double x)
-{
- long n;
- __asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x));
- return n;
-}
diff --git a/lib/libc/musl/src/math/aarch64/lroundf.c b/lib/libc/musl/src/math/aarch64/lroundf.c
@@ -1,8 +0,0 @@
-#include <math.h>
-
-long lroundf(float x)
-{
- long n;
- __asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x));
- return n;
-}
diff --git a/lib/libc/musl/src/math/lround.c b/lib/libc/musl/src/math/lround.c
@@ -1,6 +0,0 @@
-#include <math.h>
-
-long lround(double x)
-{
- return round(x);
-}
diff --git a/lib/libc/musl/src/math/lroundf.c b/lib/libc/musl/src/math/lroundf.c
@@ -1,6 +0,0 @@
-#include <math.h>
-
-long lroundf(float x)
-{
- return roundf(x);
-}
diff --git a/lib/libc/musl/src/math/lroundl.c b/lib/libc/musl/src/math/lroundl.c
@@ -1,6 +0,0 @@
-#include <math.h>
-
-long lroundl(long double x)
-{
- return roundl(x);
-}
diff --git a/lib/libc/musl/src/math/powerpc64/lround.c b/lib/libc/musl/src/math/powerpc64/lround.c
@@ -1,18 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-long lround(double x)
-{
- long n;
- __asm__ (
- "xsrdpi %1, %1\n"
- "fctid %0, %1\n" : "=d"(n), "+d"(x));
- return n;
-}
-
-#else
-
-#include "../lround.c"
-
-#endif
diff --git a/lib/libc/musl/src/math/powerpc64/lroundf.c b/lib/libc/musl/src/math/powerpc64/lroundf.c
@@ -1,18 +0,0 @@
-#include <math.h>
-
-#ifdef __VSX__
-
-long lroundf(float x)
-{
- long n;
- __asm__ (
- "xsrdpi %1, %1\n"
- "fctid %0, %1\n" : "=d"(n), "+f"(x));
- return n;
-}
-
-#else
-
-#include "../lroundf.c"
-
-#endif
diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig
@@ -853,7 +853,6 @@ const mingw32_x86_src = [_][]const u8{
"math" ++ path.sep_str ++ "fmal.c",
"math" ++ path.sep_str ++ "llrintl.c",
"math" ++ path.sep_str ++ "llroundl.c",
- "math" ++ path.sep_str ++ "lroundl.c",
"math" ++ path.sep_str ++ "tgammal.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c",
diff --git a/src/libs/musl.zig b/src/libs/musl.zig
@@ -784,8 +784,6 @@ const src_files = [_][]const u8{
"musl/src/math/aarch64/llrintf.c",
"musl/src/math/aarch64/llround.c",
"musl/src/math/aarch64/llroundf.c",
- "musl/src/math/aarch64/lround.c",
- "musl/src/math/aarch64/lroundf.c",
"musl/src/math/aarch64/nearbyint.c",
"musl/src/math/aarch64/nearbyintf.c",
"musl/src/math/acosh.c",
@@ -891,9 +889,6 @@ const src_files = [_][]const u8{
"musl/src/math/logbf.c",
"musl/src/math/logbl.c",
"musl/src/math/logl.c",
- "musl/src/math/lround.c",
- "musl/src/math/lroundf.c",
- "musl/src/math/lroundl.c",
"musl/src/math/__math_divzero.c",
"musl/src/math/__math_divzerof.c",
"musl/src/math/__math_invalid.c",
@@ -919,8 +914,6 @@ const src_files = [_][]const u8{
"musl/src/math/pow_data.c",
"musl/src/math/powerpc64/fma.c",
"musl/src/math/powerpc64/fmaf.c",
- "musl/src/math/powerpc64/lround.c",
- "musl/src/math/powerpc64/lroundf.c",
"musl/src/math/powerpc/fma.c",
"musl/src/math/powerpc/fmaf.c",
"musl/src/math/powf.c",
diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig
@@ -725,9 +725,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/logbf.c",
"musl/src/math/logbl.c",
"musl/src/math/logl.c",
- "musl/src/math/lround.c",
- "musl/src/math/lroundf.c",
- "musl/src/math/lroundl.c",
"musl/src/math/__math_divzero.c",
"musl/src/math/__math_divzerof.c",
"musl/src/math/__math_invalid.c",