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 d61242c319adec463f6f9ab0c181a5dc604901c2
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

Reply via email to