msvcrt: Import nexttowardf implementation from musl.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2021-05-14 16:12:05 +02:00 committed by Alexandre Julliard
parent ac4e675973
commit c12ff71cdc
6 changed files with 36 additions and 25 deletions

1
configure vendored
View File

@ -19640,7 +19640,6 @@ for ac_func in \
log1pf \
log2 \
log2f \
nexttowardf \
remainder \
remainderf \
remquo \

View File

@ -2680,7 +2680,6 @@ AC_CHECK_FUNCS(\
log1pf \
log2 \
log2f \
nexttowardf \
remainder \
remainderf \
remquo \

View File

@ -3492,13 +3492,44 @@ double CDECL MSVCRT_nexttoward(double num, double next)
/*********************************************************************
* nexttowardf (MSVCR120.@)
*
* Copied from musl: src/math/nexttowardf.c
*/
float CDECL MSVCRT_nexttowardf(float num, double next)
float CDECL MSVCRT_nexttowardf(float x, double y)
{
float ret = unix_funcs->nexttowardf( num, next );
if (!(_fpclass(ret) & (_FPCLASS_PN | _FPCLASS_NN
| _FPCLASS_SNAN | _FPCLASS_QNAN)) && !isinf(num))
{
unsigned int ix = *(unsigned int*)&x;
unsigned int e;
float ret;
if (isnan(x) || isnan(y))
return x + y;
if (x == y)
return y;
if (x == 0) {
ix = 1;
if (signbit(y))
ix |= 0x80000000;
} else if (x < y) {
if (signbit(x))
ix--;
else
ix++;
} else {
if (signbit(x))
ix++;
else
ix--;
}
e = ix & 0x7f800000;
/* raise overflow if ix is infinite and x is finite */
if (e == 0x7f800000) {
fp_barrierf(x + x);
*_errno() = ERANGE;
}
ret = *(float*)&ix;
/* raise underflow if ret is subnormal or zero */
if (e == 0) {
fp_barrierf(x * x + ret * ret);
*_errno() = ERANGE;
}
return ret;

View File

@ -547,19 +547,6 @@ static float CDECL unix_modff( float x, float *iptr )
return modff( x, iptr );
}
/*********************************************************************
* nexttowardf
*/
static float CDECL unix_nexttowardf(float num, double next)
{
#ifdef HAVE_NEXTTOWARDF
return nexttowardf(num, next);
#else
FIXME("not implemented\n");
return 0;
#endif
}
/*********************************************************************
* pow
*/
@ -793,7 +780,6 @@ static const struct unix_funcs funcs =
unix_logbf,
unix_modf,
unix_modff,
unix_nexttowardf,
unix_pow,
unix_powf,
unix_remainder,

View File

@ -72,7 +72,6 @@ struct unix_funcs
float (CDECL *logbf)(float x);
double (CDECL *modf)(double x, double *iptr);
float (CDECL *modff)(float x, float *iptr);
float (CDECL *nexttowardf)(float x, double y);
double (CDECL *pow)(double x, double y);
float (CDECL *powf)(float x, float y);
double (CDECL *remainder)(double x, double y);

View File

@ -567,9 +567,6 @@
/* Define to 1 if you have the <net/route.h> header file. */
#undef HAVE_NET_ROUTE_H
/* Define to 1 if you have the `nexttowardf' function. */
#undef HAVE_NEXTTOWARDF
/* Define to 1 if `_msg_ptr' is a member of `ns_msg'. */
#undef HAVE_NS_MSG__MSG_PTR