Piotr Caban : msvcrt: Import nexttowardf implementation from musl.
Alexandre Julliard
julliard at winehq.org
Fri May 14 15:47:05 CDT 2021
Module: wine
Branch: master
Commit: c12ff71cdcce2e1386e2675ccad62c15dcc7ded3
URL: https://source.winehq.org/git/wine.git/?a=commit;h=c12ff71cdcce2e1386e2675ccad62c15dcc7ded3
Author: Piotr Caban <piotr at codeweavers.com>
Date: Fri May 14 16:12:05 2021 +0200
msvcrt: Import nexttowardf implementation from musl.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
configure | 1 -
configure.ac | 1 -
dlls/msvcrt/math.c | 41 ++++++++++++++++++++++++++++++++++++-----
dlls/msvcrt/unixlib.c | 14 --------------
dlls/msvcrt/unixlib.h | 1 -
include/config.h.in | 3 ---
6 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/configure b/configure
index ae7f66fb034..886a463a92a 100755
--- a/configure
+++ b/configure
@@ -19640,7 +19640,6 @@ for ac_func in \
log1pf \
log2 \
log2f \
- nexttowardf \
remainder \
remainderf \
remquo \
diff --git a/configure.ac b/configure.ac
index 626c7674686..2b126a7c579 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2680,7 +2680,6 @@ AC_CHECK_FUNCS(\
log1pf \
log2 \
log2f \
- nexttowardf \
remainder \
remainderf \
remquo \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 6e32021373a..41096ded6e4 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -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;
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index 7c1cb0bd698..a5b59bc2cf3 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -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,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index f30f8d33fca..3d41967a2a0 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -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);
diff --git a/include/config.h.in b/include/config.h.in
index 1f2ddbe520f..56f3bc90003 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -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
More information about the wine-cvs
mailing list