| author | |
| committer | |
| log | 20b3aa3bcd55ad8f3f545f5ab0f0c2ac7122e2a2 |
| tree | a13d5935691f8877abec5b283da082f3f043ddf0 |
| parent | 23f46bcd4d1d6cca5a25ed9e7b1222b1283de7af |
Implements lround, lroundf and lroundl for libzigc
See #30978
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/3560012 files changed, 15 insertions(+), 118 deletions(-)
lib/c/math.zig+15| ... | @@ -37,6 +37,7 @@ comptime { | ... | @@ -37,6 +37,7 @@ comptime { |
| 37 | symbol(&hypotf, "hypotf"); | 37 | symbol(&hypotf, "hypotf"); |
| 38 | symbol(&hypotl, "hypotl"); | 38 | symbol(&hypotl, "hypotl"); |
| 39 | symbol(&lrintl, "lrintl"); | 39 | symbol(&lrintl, "lrintl"); |
| 40 | symbol(&lroundl, "lroundl"); | ||
| 40 | symbol(&modfl, "modfl"); | 41 | symbol(&modfl, "modfl"); |
| 41 | symbol(&rintl, "rintl"); | 42 | symbol(&rintl, "rintl"); |
| 42 | } | 43 | } |
| ... | @@ -76,6 +77,8 @@ comptime { | ... | @@ -76,6 +77,8 @@ comptime { |
| 76 | symbol(&log1pf, "log1pf"); | 77 | symbol(&log1pf, "log1pf"); |
| 77 | symbol(&lrint, "lrint"); | 78 | symbol(&lrint, "lrint"); |
| 78 | symbol(&lrintf, "lrintf"); | 79 | symbol(&lrintf, "lrintf"); |
| 80 | symbol(&lround, "lround"); | ||
| 81 | symbol(&lroundf, "lroundf"); | ||
| 79 | symbol(&modf, "modf"); | 82 | symbol(&modf, "modf"); |
| 80 | symbol(&nan, "nan"); | 83 | symbol(&nan, "nan"); |
| 81 | symbol(&nanf, "nanf"); | 84 | symbol(&nanf, "nanf"); |
| ... | @@ -278,6 +281,18 @@ fn lrintl(x: c_longdouble) callconv(.c) c_long { | ... | @@ -278,6 +281,18 @@ fn lrintl(x: c_longdouble) callconv(.c) c_long { |
| 278 | return @trunc(rintl(x)); | 281 | return @trunc(rintl(x)); |
| 279 | } | 282 | } |
| 280 | 283 | ||
| 284 | fn lround(x: f64) callconv(.c) c_long { | ||
| 285 | return @round(x); | ||
| 286 | } | ||
| 287 | |||
| 288 | fn lroundf(x: f32) callconv(.c) c_long { | ||
| 289 | return @round(x); | ||
| 290 | } | ||
| 291 | |||
| 292 | fn lroundl(x: c_longdouble) callconv(.c) c_long { | ||
| 293 | return @round(x); | ||
| 294 | } | ||
| 295 | |||
| 281 | fn modfGeneric(comptime T: type, x: T, iptr: *T) T { | 296 | fn modfGeneric(comptime T: type, x: T, iptr: *T) T { |
| 282 | if (math.isNegativeInf(x)) { | 297 | if (math.isNegativeInf(x)) { |
| 283 | iptr.* = -math.inf(T); | 298 | 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 | |||
| 10 | long | ||
| 11 | lroundl (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 | |||
| 3 | long 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 | |||
| 3 | long 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 | |||
| 3 | long 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 | |||
| 3 | long 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 | |||
| 3 | long 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 | |||
| 5 | long 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 | |||
| 5 | long 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{ | ... | @@ -853,7 +853,6 @@ const mingw32_x86_src = [_][]const u8{ |
| 853 | "math" ++ path.sep_str ++ "fmal.c", | 853 | "math" ++ path.sep_str ++ "fmal.c", |
| 854 | "math" ++ path.sep_str ++ "llrintl.c", | 854 | "math" ++ path.sep_str ++ "llrintl.c", |
| 855 | "math" ++ path.sep_str ++ "llroundl.c", | 855 | "math" ++ path.sep_str ++ "llroundl.c", |
| 856 | "math" ++ path.sep_str ++ "lroundl.c", | ||
| 857 | "math" ++ path.sep_str ++ "tgammal.c", | 856 | "math" ++ path.sep_str ++ "tgammal.c", |
| 858 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S", | 857 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S", |
| 859 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c", | 858 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c", |
src/libs/musl.zig-7| ... | @@ -784,8 +784,6 @@ const src_files = [_][]const u8{ | ... | @@ -784,8 +784,6 @@ const src_files = [_][]const u8{ |
| 784 | "musl/src/math/aarch64/llrintf.c", | 784 | "musl/src/math/aarch64/llrintf.c", |
| 785 | "musl/src/math/aarch64/llround.c", | 785 | "musl/src/math/aarch64/llround.c", |
| 786 | "musl/src/math/aarch64/llroundf.c", | 786 | "musl/src/math/aarch64/llroundf.c", |
| 787 | "musl/src/math/aarch64/lround.c", | ||
| 788 | "musl/src/math/aarch64/lroundf.c", | ||
| 789 | "musl/src/math/aarch64/nearbyint.c", | 787 | "musl/src/math/aarch64/nearbyint.c", |
| 790 | "musl/src/math/aarch64/nearbyintf.c", | 788 | "musl/src/math/aarch64/nearbyintf.c", |
| 791 | "musl/src/math/acosh.c", | 789 | "musl/src/math/acosh.c", |
| ... | @@ -891,9 +889,6 @@ const src_files = [_][]const u8{ | ... | @@ -891,9 +889,6 @@ const src_files = [_][]const u8{ |
| 891 | "musl/src/math/logbf.c", | 889 | "musl/src/math/logbf.c", |
| 892 | "musl/src/math/logbl.c", | 890 | "musl/src/math/logbl.c", |
| 893 | "musl/src/math/logl.c", | 891 | "musl/src/math/logl.c", |
| 894 | "musl/src/math/lround.c", | ||
| 895 | "musl/src/math/lroundf.c", | ||
| 896 | "musl/src/math/lroundl.c", | ||
| 897 | "musl/src/math/__math_divzero.c", | 892 | "musl/src/math/__math_divzero.c", |
| 898 | "musl/src/math/__math_divzerof.c", | 893 | "musl/src/math/__math_divzerof.c", |
| 899 | "musl/src/math/__math_invalid.c", | 894 | "musl/src/math/__math_invalid.c", |
| ... | @@ -919,8 +914,6 @@ const src_files = [_][]const u8{ | ... | @@ -919,8 +914,6 @@ const src_files = [_][]const u8{ |
| 919 | "musl/src/math/pow_data.c", | 914 | "musl/src/math/pow_data.c", |
| 920 | "musl/src/math/powerpc64/fma.c", | 915 | "musl/src/math/powerpc64/fma.c", |
| 921 | "musl/src/math/powerpc64/fmaf.c", | 916 | "musl/src/math/powerpc64/fmaf.c", |
| 922 | "musl/src/math/powerpc64/lround.c", | ||
| 923 | "musl/src/math/powerpc64/lroundf.c", | ||
| 924 | "musl/src/math/powerpc/fma.c", | 917 | "musl/src/math/powerpc/fma.c", |
| 925 | "musl/src/math/powerpc/fmaf.c", | 918 | "musl/src/math/powerpc/fmaf.c", |
| 926 | "musl/src/math/powf.c", | 919 | "musl/src/math/powf.c", |
src/libs/wasi_libc.zig-3| ... | @@ -725,9 +725,6 @@ const libc_top_half_src_files = [_][]const u8{ | ... | @@ -725,9 +725,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 725 | "musl/src/math/logbf.c", | 725 | "musl/src/math/logbf.c", |
| 726 | "musl/src/math/logbl.c", | 726 | "musl/src/math/logbl.c", |
| 727 | "musl/src/math/logl.c", | 727 | "musl/src/math/logl.c", |
| 728 | "musl/src/math/lround.c", | ||
| 729 | "musl/src/math/lroundf.c", | ||
| 730 | "musl/src/math/lroundl.c", | ||
| 731 | "musl/src/math/__math_divzero.c", | 728 | "musl/src/math/__math_divzero.c", |
| 732 | "musl/src/math/__math_divzerof.c", | 729 | "musl/src/math/__math_divzerof.c", |
| 733 | "musl/src/math/__math_invalid.c", | 730 | "musl/src/math/__math_invalid.c", |