Skip to content

Commit e375b69

Browse files
Cynerdxiaoxiang781216
authored andcommitted
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čí <kkoci@elektroline.cz>
1 parent 88cf4fc commit e375b69

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

libs/libm/libm/lib_truncl.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <nuttx/config.h>
3636
#include <nuttx/compiler.h>
3737

38+
#include <assert.h>
3839
#include <stdint.h>
3940
#include <float.h>
4041
#include <math.h>
@@ -44,9 +45,18 @@
4445
****************************************************************************/
4546

4647
#ifdef CONFIG_HAVE_LONG_DOUBLE
47-
static const long double toint = 1 / LDBL_EPSILON;
48+
#if LDBL_MANT_DIG == DBL_MANT_DIG
49+
50+
/* Cover case when double is the same as long double (64 bit ieee754). */
51+
52+
long double truncl(long double x)
53+
{
54+
return trunc(x);
55+
}
4856

49-
/* FIXME This will only work if long double is 64 bit and little endian */
57+
#elif LDBL_MANT_DIG == 64
58+
59+
static const long double toint = 1 / LDBL_EPSILON;
5060

5161
union ldshape
5262
{
@@ -100,4 +110,13 @@ long double truncl(long double x)
100110
x += y;
101111
return s ? -x : x;
102112
}
113+
114+
#else
115+
116+
long double truncl(long double x)
117+
{
118+
PANIC(); /* FIX ME */
119+
}
120+
121+
#endif
103122
#endif

0 commit comments

Comments
 (0)