This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch releases/13.0 in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e375b69e086ef7f6236713e5d12bddf0f8e93211 Author: Karel Kočí <[email protected]> AuthorDate: Tue Jun 30 10:21:21 2026 +0200 libs/libm: correct implementation of truncl if long double is double This reuses implementation of trunc in case long double has same size as double. The previous implementation is used only in case x87 80-bit float point is the long double. In other cases the logic is intentionally replaced with panic to not provide a wrong result. Signed-off-by: Karel Kočí <[email protected]> --- libs/libm/libm/lib_truncl.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libs/libm/libm/lib_truncl.c b/libs/libm/libm/lib_truncl.c index 8dc245e3eea..48aabbba872 100644 --- a/libs/libm/libm/lib_truncl.c +++ b/libs/libm/libm/lib_truncl.c @@ -35,6 +35,7 @@ #include <nuttx/config.h> #include <nuttx/compiler.h> +#include <assert.h> #include <stdint.h> #include <float.h> #include <math.h> @@ -44,9 +45,18 @@ ****************************************************************************/ #ifdef CONFIG_HAVE_LONG_DOUBLE -static const long double toint = 1 / LDBL_EPSILON; +#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); +} -/* FIXME This will only work if long double is 64 bit and little endian */ +#elif LDBL_MANT_DIG == 64 + +static const long double toint = 1 / LDBL_EPSILON; union ldshape { @@ -100,4 +110,13 @@ long double truncl(long double x) x += y; return s ? -x : x; } + +#else + +long double truncl(long double x) +{ + PANIC(); /* FIX ME */ +} + +#endif #endif
