From 30634165980deaeead9f4e71e0ff6a5c9d897776 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 14 Jul 2025 22:39:34 -0400 Subject: usr: libc: Add math.h + musl math impl port Signed-off-by: Ian Moffett --- lib/libc/src/musl-math/nearbyint.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/libc/src/musl-math/nearbyint.c (limited to 'lib/libc/src/musl-math/nearbyint.c') diff --git a/lib/libc/src/musl-math/nearbyint.c b/lib/libc/src/musl-math/nearbyint.c new file mode 100644 index 0000000..f4e8aac --- /dev/null +++ b/lib/libc/src/musl-math/nearbyint.c @@ -0,0 +1,20 @@ +#include +#include + +/* nearbyint is the same as rint, but it must not raise the inexact exception */ + +double nearbyint(double x) +{ +#ifdef FE_INEXACT + #pragma STDC FENV_ACCESS ON + int e; + + e = fetestexcept(FE_INEXACT); +#endif + x = rint(x); +#ifdef FE_INEXACT + if (!e) + feclearexcept(FE_INEXACT); +#endif + return x; +} -- cgit v1.2.3