Commit 9fd9ebcb authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Use the cosh() implementation from the bundled musl library.

With the changes from 60d178b4.
parent 66bef6db
......@@ -2155,49 +2155,6 @@ double CDECL cos( double x )
extern double __expo2(double x, double sign);
/*********************************************************************
* cosh (MSVCRT.@)
*
* Copied from musl: src/math/cosh.c
*/
double CDECL cosh( double x )
{
UINT64 ux = *(UINT64*)&x;
UINT64 sign = ux & 0x8000000000000000ULL;
UINT32 w;
double t;
/* |x| */
ux &= (uint64_t)-1 / 2;
x = *(double*)&ux;
w = ux >> 32;
/* |x| < log(2) */
if (w < 0x3fe62e42) {
if (w < 0x3ff00000 - (26 << 20)) {
fp_barrier(x + 0x1p120f);
return 1;
}
t = expm1(x);
return 1 + t * t / (2 * (1 + t));
}
/* |x| < log(DBL_MAX) */
if (w < 0x40862e42) {
t = exp(x);
/* note: if x>log(0x1p26) then the 1/t is not needed */
return 0.5 * (t + 1 / t);
}
/* |x| > log(DBL_MAX) or nan */
/* note: the result is stored to handle overflow */
if (ux > 0x7ff0000000000000ULL)
*(UINT64*)&t = ux | sign | 0x0008000000000000ULL;
else
t = __expo2(x, 1.0);
return t;
}
/* Copied from musl: src/math/exp_data.c */
static const UINT64 exp_T[] = {
0x0ULL, 0x3ff0000000000000ULL,
......
......@@ -7,6 +7,7 @@
double __cdecl cosh(double x)
{
union {double f; uint64_t i;} u = {.f = x};
uint64_t sign = u.i & 0x8000000000000000ULL;
uint32_t w;
double t;
......@@ -35,6 +36,10 @@ double __cdecl cosh(double x)
/* |x| > log(DBL_MAX) or nan */
/* note: the result is stored to handle overflow */
if (w > 0x7ff00000) {
u.i |= sign | 0x0008000000000000ULL;
return u.f;
}
t = __expo2(x, 1.0);
return t;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment