mirror of
https://github.com/fluencelabs/musl
synced 2025-07-01 15:42:05 +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)) */
|
/* acosh(x) = log(x + sqrt(x*x-1)) */
|
||||||
long double acoshl(long double x)
|
long double acoshl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
int e = u.i.se & 0x7fff;
|
||||||
struct{uint64_t m; int16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
|
|
||||||
if (u.i.se < 0x3fff + 1)
|
if (e < 0x3fff + 1)
|
||||||
/* x < 2, invalid if x < 1 or nan */
|
/* x < 2, invalid if x < 1 or nan */
|
||||||
return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1)));
|
return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1)));
|
||||||
if (u.i.se < 0x3fff + 32)
|
if (e < 0x3fff + 32)
|
||||||
/* x < 0x1p32 */
|
/* x < 0x1p32 */
|
||||||
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
||||||
return logl(x) + 0.693147180559945309417232121458176568L;
|
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) */
|
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
|
||||||
long double asinhl(long double x)
|
long double asinhl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
|
||||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
unsigned e = u.i.se & 0x7fff;
|
unsigned e = u.i.se & 0x7fff;
|
||||||
unsigned s = u.i.se >> 15;
|
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) */
|
/* 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)
|
long double atanhl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
|
||||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
unsigned e = u.i.se & 0x7fff;
|
unsigned e = u.i.se & 0x7fff;
|
||||||
unsigned s = u.i.se >> 15;
|
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
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||||
long double coshl(long double x)
|
long double coshl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
|
||||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
unsigned ex = u.i.se & 0x7fff;
|
unsigned ex = u.i.se & 0x7fff;
|
||||||
uint32_t w;
|
uint32_t w;
|
||||||
long double t;
|
long double t;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
#include <math.h>
|
#include "libm.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 */
|
|
||||||
|
|
||||||
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double frexpl(long double x, int *e)
|
long double frexpl(long double x, int *e)
|
||||||
{
|
{
|
||||||
union { long double ld; uint16_t hw[5]; } y = { x };
|
return frexp(x, e);
|
||||||
int ee = y.hw[4]&0x7fff;
|
}
|
||||||
|
#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 (!ee) {
|
||||||
if (x) {
|
if (x) {
|
||||||
x = frexpl(x*0x1p64, e);
|
x = frexpl(x*0x1p120, e);
|
||||||
*e -= 64;
|
*e -= 120;
|
||||||
} else *e = 0;
|
} else *e = 0;
|
||||||
return x;
|
return x;
|
||||||
} else if (ee == 0x7fff) {
|
} else if (ee == 0x7fff) {
|
||||||
@ -22,16 +22,8 @@ long double frexpl(long double x, int *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*e = ee - 0x3ffe;
|
*e = ee - 0x3ffe;
|
||||||
y.hw[4] &= 0x8000;
|
u.i.se &= 0x8000;
|
||||||
y.hw[4] |= 0x3ffe;
|
u.i.se |= 0x3ffe;
|
||||||
return y.ld;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
long double frexpl(long double x, int *e)
|
|
||||||
{
|
|
||||||
return frexp(x, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,10 +8,7 @@ long double sinhl(long double x)
|
|||||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||||
long double sinhl(long double x)
|
long double sinhl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
|
||||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
unsigned ex = u.i.se & 0x7fff;
|
unsigned ex = u.i.se & 0x7fff;
|
||||||
long double h, t, absx;
|
long double h, t, absx;
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
long double sqrtl(long double x)
|
long double sqrtl(long double x)
|
||||||
{
|
{
|
||||||
/* FIXME: implement sqrtl in C. At least this works for now on
|
/* FIXME: implement in C, this is for LDBL_MANT_DIG == 64 only */
|
||||||
* ARM (which uses ld64), the only arch without sqrtl asm
|
|
||||||
* that's supported so far. */
|
|
||||||
return sqrt(x);
|
return sqrt(x);
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,7 @@ long double tanhl(long double x)
|
|||||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||||
long double tanhl(long double x)
|
long double tanhl(long double x)
|
||||||
{
|
{
|
||||||
union {
|
union ldshape u = {x};
|
||||||
long double f;
|
|
||||||
struct{uint64_t m; uint16_t se; uint16_t pad;} i;
|
|
||||||
} u = {.f = x};
|
|
||||||
unsigned ex = u.i.se & 0x7fff;
|
unsigned ex = u.i.se & 0x7fff;
|
||||||
unsigned sign = u.i.se & 0x8000;
|
unsigned sign = u.i.se & 0x8000;
|
||||||
uint32_t w;
|
uint32_t w;
|
||||||
|
Reference in New Issue
Block a user