mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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:
parent
9f4b4faf47
commit
d61242c319
1 changed files with 21 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue