msvcrt: Import exp2f implementation from musl.
Signed-off-by: Piotr Caban <piotr@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
2fb789f5c6
commit
07e31f4eaf
|
@ -19620,8 +19620,7 @@ $as_echo "#define HAVE_ISNAN 1" >>confdefs.h
|
|||
fi
|
||||
|
||||
for ac_func in \
|
||||
exp2 \
|
||||
exp2f
|
||||
exp2
|
||||
|
||||
do :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
|
|
|
@ -2659,8 +2659,7 @@ then
|
|||
fi
|
||||
|
||||
AC_CHECK_FUNCS(\
|
||||
exp2 \
|
||||
exp2f
|
||||
exp2
|
||||
)
|
||||
LIBS="$ac_save_LIBS"
|
||||
|
||||
|
|
|
@ -7025,12 +7025,64 @@ double CDECL exp2(double x)
|
|||
|
||||
/*********************************************************************
|
||||
* exp2f (MSVCR120.@)
|
||||
*
|
||||
* Copied from musl: src/math/exp2f.c
|
||||
*/
|
||||
float CDECL exp2f(float x)
|
||||
{
|
||||
float ret = unix_funcs->exp2f( x );
|
||||
if (isfinite(x) && !isfinite(ret)) *_errno() = ERANGE;
|
||||
return ret;
|
||||
static const UINT64 T[] = {
|
||||
0x3ff0000000000000ULL, 0x3fefd9b0d3158574ULL, 0x3fefb5586cf9890fULL, 0x3fef9301d0125b51ULL,
|
||||
0x3fef72b83c7d517bULL, 0x3fef54873168b9aaULL, 0x3fef387a6e756238ULL, 0x3fef1e9df51fdee1ULL,
|
||||
0x3fef06fe0a31b715ULL, 0x3feef1a7373aa9cbULL, 0x3feedea64c123422ULL, 0x3feece086061892dULL,
|
||||
0x3feebfdad5362a27ULL, 0x3feeb42b569d4f82ULL, 0x3feeab07dd485429ULL, 0x3feea47eb03a5585ULL,
|
||||
0x3feea09e667f3bcdULL, 0x3fee9f75e8ec5f74ULL, 0x3feea11473eb0187ULL, 0x3feea589994cce13ULL,
|
||||
0x3feeace5422aa0dbULL, 0x3feeb737b0cdc5e5ULL, 0x3feec49182a3f090ULL, 0x3feed503b23e255dULL,
|
||||
0x3feee89f995ad3adULL, 0x3feeff76f2fb5e47ULL, 0x3fef199bdd85529cULL, 0x3fef3720dcef9069ULL,
|
||||
0x3fef5818dcfba487ULL, 0x3fef7c97337b9b5fULL, 0x3fefa4afa2a490daULL, 0x3fefd0765b6e4540ULL
|
||||
};
|
||||
static const double C[] = {
|
||||
0x1.c6af84b912394p-5, 0x1.ebfce50fac4f3p-3, 0x1.62e42ff0c52d6p-1
|
||||
};
|
||||
static const double shift = 0x1.8p+52 / (1 << 5);
|
||||
|
||||
double kd, xd, z, r, r2, y, s;
|
||||
UINT32 abstop;
|
||||
UINT64 ki, t;
|
||||
|
||||
xd = x;
|
||||
abstop = (*(UINT32*)&x >> 20) & 0x7ff;
|
||||
if (abstop >= 0x430) {
|
||||
/* |x| >= 128 or x is nan. */
|
||||
if (*(UINT32*)&x == 0xff800000)
|
||||
return 0.0f;
|
||||
if (abstop >= 0x7f8)
|
||||
return x + x;
|
||||
if (x > 0.0f) {
|
||||
*_errno() = ERANGE;
|
||||
return fp_barrierf(x * FLT_MAX);
|
||||
}
|
||||
if (x <= -150.0f) {
|
||||
fp_barrierf(x - 0x1p120);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k, N = 1 << 5. */
|
||||
kd = xd + shift;
|
||||
ki = *(UINT64*)&kd;
|
||||
kd -= shift; /* k/(1<<5) for int k. */
|
||||
r = xd - kd;
|
||||
|
||||
/* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
|
||||
t = T[ki % (1 << 5)];
|
||||
t += ki << (52 - 5);
|
||||
s = *(double*)&t;
|
||||
z = C[0] * r + C[1];
|
||||
r2 = r * r;
|
||||
y = C[2] * r + 1;
|
||||
y = z * r2 + y;
|
||||
y = y * s;
|
||||
return y;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
|
@ -70,18 +70,6 @@ static double CDECL unix_exp2( double x )
|
|||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* exp2f
|
||||
*/
|
||||
static float CDECL unix_exp2f( float x )
|
||||
{
|
||||
#ifdef HAVE_EXP2F
|
||||
return exp2f(x);
|
||||
#else
|
||||
return unix_exp2(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* pow
|
||||
*/
|
||||
|
@ -103,7 +91,6 @@ static const struct unix_funcs funcs =
|
|||
unix_exp,
|
||||
unix_expf,
|
||||
unix_exp2,
|
||||
unix_exp2f,
|
||||
unix_pow,
|
||||
unix_powf,
|
||||
};
|
||||
|
|
|
@ -26,7 +26,6 @@ struct unix_funcs
|
|||
double (CDECL *exp)(double x);
|
||||
float (CDECL *expf)(float x);
|
||||
double (CDECL *exp2)(double x);
|
||||
float (CDECL *exp2f)(float x);
|
||||
double (CDECL *pow)(double x, double y);
|
||||
float (CDECL *powf)(float x, float y);
|
||||
};
|
||||
|
|
|
@ -95,9 +95,6 @@
|
|||
/* Define to 1 if you have the `exp2' function. */
|
||||
#undef HAVE_EXP2
|
||||
|
||||
/* Define to 1 if you have the `exp2f' function. */
|
||||
#undef HAVE_EXP2F
|
||||
|
||||
/* Define to 1 if you have the `F3DAudioInitialize8' function. */
|
||||
#undef HAVE_F3DAUDIOINITIALIZE8
|
||||
|
||||
|
|
Loading…
Reference in New Issue