From bab1e1f21d3aedba31e46ed67f73fcd87e36a167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 2 Mar 2026 14:15:16 +0100 Subject: [PATCH] libm: fix truncl when long double has same size as double MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The truncl implementation expects 80 bit little endian representation of the floating point number. That is valid for x86 but not for example arm. On arm long double is the same as double. This was discovered with newer version of GCC (15.2.0) that started emitting warning: libm/lib_truncl.c: In function 'truncl': libm/lib_truncl.c:68:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized] 68 | int e = u.i.se & 0x7fff; | ~~~^~~ libm/lib_truncl.c:63:17: note: 'u' declared here 63 | union ldshape u = | ^ libm/lib_truncl.c:69:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized] 69 | int s = u.i.se >> 15; | ~~~^~~ libm/lib_truncl.c:63:17: note: 'u' declared here 63 | union ldshape u = | ^ libm/lib_truncl.c:63:17: error: 'u.i.se' is used uninitialized [-Werror=uninitialized] Signed-off-by: Karel Kočí --- libs/libm/libm/lib_truncl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/libm/libm/lib_truncl.c b/libs/libm/libm/lib_truncl.c index 8dc245e3eea37..2c5511b4fbc12 100644 --- a/libs/libm/libm/lib_truncl.c +++ b/libs/libm/libm/lib_truncl.c @@ -44,9 +44,20 @@ ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE +#if LDBL_MANT_DIG == DBL_MANT_DIG + +/* Cover case when double is the same as long double (64 bit ieee754). */ + +long double truncl(long double x) +{ + return trunc(x); +} + +#else + static const long double toint = 1 / LDBL_EPSILON; -/* FIXME This will only work if long double is 64 bit and little endian */ +/* FIXME This will only work if long double is 80 bit and little endian */ union ldshape { @@ -101,3 +112,4 @@ long double truncl(long double x) return s ? -x : x; } #endif +#endif