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>
This commit is contained in:
Karel Kočí 2026-06-30 10:21:21 +02:00 committed by Alan C. Assis
parent 9f4b4faf47
commit d61242c319

View file

@ -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
/* FIXME This will only work if long double is 64 bit and little endian */
/* Cover case when double is the same as long double (64 bit ieee754). */
long double truncl(long double x)
{
return trunc(x);
}
#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