This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b6d854ca14fc84983541e5cd1b18fab1404ff37a Author: Marco Casaroli <[email protected]> AuthorDate: Mon Oct 19 02:29:59 2026 +0200 libs/libm: Fix fabs() of negative zero. fabs(), fabsf() and fabsl() returned x when x < 0 was false, so fabs(-0.0) returned -0.0. copysign() uses fabs(), so copysign(-0.0, 1.0) also returned -0.0. Test the sign bit with signbit() instead. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libm/libm/lib_fabs.c | 2 +- libs/libm/libm/lib_fabsf.c | 2 +- libs/libm/libm/lib_fabsl.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/libm/libm/lib_fabs.c b/libs/libm/libm/lib_fabs.c index 02b19810214..02b48e67ff6 100644 --- a/libs/libm/libm/lib_fabs.c +++ b/libs/libm/libm/lib_fabs.c @@ -40,6 +40,6 @@ #ifdef CONFIG_HAVE_DOUBLE double fabs(double x) { - return ((x < 0) ? -x : x); + return signbit(x) ? -x : x; } #endif diff --git a/libs/libm/libm/lib_fabsf.c b/libs/libm/libm/lib_fabsf.c index 5182213cce8..373047b247c 100644 --- a/libs/libm/libm/lib_fabsf.c +++ b/libs/libm/libm/lib_fabsf.c @@ -38,6 +38,6 @@ #ifndef CONFIG_LIBM_ARCH_FABSF float fabsf(float x) { - return ((x < 0) ? -x : x); + return signbit(x) ? -x : x; } #endif diff --git a/libs/libm/libm/lib_fabsl.c b/libs/libm/libm/lib_fabsl.c index e7ab05607be..7ab5b7b30ea 100644 --- a/libs/libm/libm/lib_fabsl.c +++ b/libs/libm/libm/lib_fabsl.c @@ -40,6 +40,6 @@ #ifdef CONFIG_HAVE_LONG_DOUBLE long double fabsl(long double x) { - return ((x < 0) ? -x : x); + return signbit(x) ? -x : x; } #endif
