mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 15:11:55 +00:00
math: long double fix (use ldshape union)
* use new ldshape union consistently * add ld128 support to frexpl * simplify sqrtl comment (ld64 is not just arm)
This commit is contained in:
@ -9,15 +9,13 @@ long double acoshl(long double x)
|
||||
/* acosh(x) = log(x + sqrt(x*x-1)) */
|
||||
long double acoshl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; int16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
int e = u.i.se & 0x7fff;
|
||||
|
||||
if (u.i.se < 0x3fff + 1)
|
||||
if (e < 0x3fff + 1)
|
||||
/* x < 2, invalid if x < 1 or nan */
|
||||
return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1)));
|
||||
if (u.i.se < 0x3fff + 32)
|
||||
if (e < 0x3fff + 32)
|
||||
/* x < 0x1p32 */
|
||||
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
||||
return logl(x) + 0.693147180559945309417232121458176568L;
|
||||
|
@ -9,10 +9,7 @@ long double asinhl(long double x)
|
||||
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
|
||||
long double asinhl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
unsigned e = u.i.se & 0x7fff;
|
||||
unsigned s = u.i.se >> 15;
|
||||
|
||||
|
@ -9,10 +9,7 @@ long double atanhl(long double x)
|
||||
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
|
||||
long double atanhl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
unsigned e = u.i.se & 0x7fff;
|
||||
unsigned s = u.i.se >> 15;
|
||||
|
||||
|
@ -8,10 +8,7 @@ long double coshl(long double x)
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
long double coshl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
unsigned ex = u.i.se & 0x7fff;
|
||||
uint32_t w;
|
||||
long double t;
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <float.h>
|
||||
|
||||
#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
|
||||
/* This version is for 80-bit little endian long double */
|
||||
#include "libm.h"
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double frexpl(long double x, int *e)
|
||||
{
|
||||
union { long double ld; uint16_t hw[5]; } y = { x };
|
||||
int ee = y.hw[4]&0x7fff;
|
||||
return frexp(x, e);
|
||||
}
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
long double frexpl(long double x, int *e)
|
||||
{
|
||||
union ldshape u = {x};
|
||||
int ee = u.i.se & 0x7fff;
|
||||
|
||||
if (!ee) {
|
||||
if (x) {
|
||||
x = frexpl(x*0x1p64, e);
|
||||
*e -= 64;
|
||||
x = frexpl(x*0x1p120, e);
|
||||
*e -= 120;
|
||||
} else *e = 0;
|
||||
return x;
|
||||
} else if (ee == 0x7fff) {
|
||||
@ -22,16 +22,8 @@ long double frexpl(long double x, int *e)
|
||||
}
|
||||
|
||||
*e = ee - 0x3ffe;
|
||||
y.hw[4] &= 0x8000;
|
||||
y.hw[4] |= 0x3ffe;
|
||||
return y.ld;
|
||||
u.i.se &= 0x8000;
|
||||
u.i.se |= 0x3ffe;
|
||||
return u.f;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
long double frexpl(long double x, int *e)
|
||||
{
|
||||
return frexp(x, e);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,10 +8,7 @@ long double sinhl(long double x)
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
long double sinhl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
unsigned ex = u.i.se & 0x7fff;
|
||||
long double h, t, absx;
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
long double sqrtl(long double x)
|
||||
{
|
||||
/* FIXME: implement sqrtl in C. At least this works for now on
|
||||
* ARM (which uses ld64), the only arch without sqrtl asm
|
||||
* that's supported so far. */
|
||||
/* FIXME: implement in C, this is for LDBL_MANT_DIG == 64 only */
|
||||
return sqrt(x);
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ long double tanhl(long double x)
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
long double tanhl(long double x)
|
||||
{
|
||||
union {
|
||||
long double f;
|
||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
||||
} u = {.f = x};
|
||||
union ldshape u = {x};
|
||||
unsigned ex = u.i.se & 0x7fff;
|
||||
unsigned sign = u.i.se & 0x8000;
|
||||
uint32_t w;
|
||||
|
Reference in New Issue
Block a user