From 20b3aa3bcd55ad8f3f545f5ab0f0c2ac7122e2a2 Mon Sep 17 00:00:00 2001 From: Pivok Date: Sun, 7 Jun 2026 23:08:14 +0200 Subject: [PATCH] libzigc: lround lroundf lroundl (#35600) Implements lround, lroundf and lroundl for libzigc See #30978 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35600 --- lib/c/math.zig | 15 +++++++++ lib/libc/mingw/math/lroundl.c | 37 ---------------------- lib/libc/musl/src/math/aarch64/lround.c | 8 ----- lib/libc/musl/src/math/aarch64/lroundf.c | 8 ----- lib/libc/musl/src/math/lround.c | 6 ---- lib/libc/musl/src/math/lroundf.c | 6 ---- lib/libc/musl/src/math/lroundl.c | 6 ---- lib/libc/musl/src/math/powerpc64/lround.c | 18 ----------- lib/libc/musl/src/math/powerpc64/lroundf.c | 18 ----------- src/libs/mingw.zig | 1 - src/libs/musl.zig | 7 ---- src/libs/wasi_libc.zig | 3 -- 12 files changed, 15 insertions(+), 118 deletions(-) delete mode 100644 lib/libc/mingw/math/lroundl.c delete mode 100644 lib/libc/musl/src/math/aarch64/lround.c delete mode 100644 lib/libc/musl/src/math/aarch64/lroundf.c delete mode 100644 lib/libc/musl/src/math/lround.c delete mode 100644 lib/libc/musl/src/math/lroundf.c delete mode 100644 lib/libc/musl/src/math/lroundl.c delete mode 100644 lib/libc/musl/src/math/powerpc64/lround.c delete mode 100644 lib/libc/musl/src/math/powerpc64/lroundf.c diff --git a/lib/c/math.zig b/lib/c/math.zig index fe6832f55b783f243436abcf47169295c8c2c014..b1ff37c04e0f454024a0e5e45590cecb34bb0df1 100644 --- 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 deleted file mode 100644 index b4584a896d3e0190c88049a9bebfeb26c48916ed..0000000000000000000000000000000000000000 --- a/lib/libc/mingw/math/lroundl.c +++ /dev/null @@ -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 -#include -#include - -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 deleted file mode 100644 index 85656c78d1c334a1618b2fa606670ae8e1038c5b..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/aarch64/lround.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -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 deleted file mode 100644 index 32e51f3cc3c738214bde60d0873532415cdd4acc..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/aarch64/lroundf.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -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 deleted file mode 100644 index b8b795470f1868d831e7c2893c7f3b7f019ddbdb..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/lround.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -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 deleted file mode 100644 index c4707e7db712cd545915efea603173e21efc709e..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/lroundf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -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 deleted file mode 100644 index 094fdf6483842e90a9fac200394255d02bb8073d..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/lroundl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -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 deleted file mode 100644 index ee4d1143c33de9b15f09ba3d79b5704a4187d1a4..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/powerpc64/lround.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#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 deleted file mode 100644 index 033094ffb2ccd645253b1a2b7338862af7455e54..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/powerpc64/lroundf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#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 index 384af94084d98f65316f16f74c019e5a57292dfc..c3a1cf2849ec5d1f7c379650616bb29bce69ad73 100644 --- 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 index 2f56a417f2984e66d696830c5ecdf9dd40e4816a..fcf179894c6d6f0d542f04fb925788c76f82ca1a 100644 --- 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 index f5025666f61406a430b51ac582d147358803eefe..561966b01707194d277afc0d5afecb241a68f732 100644 --- 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", -- 2.54.0