Commit bb9f97c4 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Import tanhf implementation from musl.

parent 3171dccb
......@@ -1512,9 +1512,43 @@ float CDECL tanf( float x )
*/
float CDECL tanhf( float x )
{
float ret = unix_funcs->tanhf(x);
if (!isfinite(x)) return math_error(_DOMAIN, "tanhf", x, 0, ret);
return ret;
UINT32 ui = *(UINT32*)&x;
int sign;
float t;
/* x = |x| */
sign = ui >> 31;
ui &= 0x7fffffff;
x = *(float*)&ui;
if (ui > 0x3f0c9f54) {
/* |x| > log(3)/2 ~= 0.5493 or nan */
if (ui > 0x41200000) {
#if _MSVCR_VER < 140
if (isnan(x))
return math_error(_DOMAIN, "tanhf", x, 0, x);
#endif
/* |x| > 10 */
fp_barrierf(x + 0x1p120f);
t = 1 + 0 / x;
} else {
t = __expm1f(2 * x);
t = 1 - 2 / (t + 2);
}
} else if (ui > 0x3e82c578) {
/* |x| > log(5/3)/2 ~= 0.2554 */
t = __expm1f(2 * x);
t = t / (t + 2);
} else if (ui >= 0x00800000) {
/* |x| >= 0x1p-126 */
t = __expm1f(-2 * x);
t = -t / (t + 2);
} else {
/* |x| is subnormal */
fp_barrierf(x * x);
t = x;
}
return sign ? -t : t;
}
/*********************************************************************
......
......@@ -269,14 +269,6 @@ static float CDECL unix_powf( float x, float y )
}
/*********************************************************************
* tanhf
*/
static float CDECL unix_tanhf( float x )
{
return tanhf( x );
}
/*********************************************************************
* tgamma
*/
static double CDECL unix_tgamma(double x)
......@@ -327,7 +319,6 @@ static const struct unix_funcs funcs =
unix_log2f,
unix_pow,
unix_powf,
unix_tanhf,
unix_tgamma,
unix_tgammaf,
};
......
......@@ -46,7 +46,6 @@ struct unix_funcs
float (CDECL *log2f)(float x);
double (CDECL *pow)(double x, double y);
float (CDECL *powf)(float x, float y);
float (CDECL *tanhf)(float x);
double (CDECL *tgamma)(double x);
float (CDECL *tgammaf)(float x);
};
......
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