diff --git a/configure b/configure index e6409e264f9..4846c93e270 100755 --- a/configure +++ b/configure @@ -19512,8 +19512,6 @@ for ac_func in \ expm1f \ fma \ fmaf \ - ilogb \ - ilogbf \ j0 \ j1 \ jn \ diff --git a/configure.ac b/configure.ac index f70329b41ae..d09fedccbb1 100644 --- a/configure.ac +++ b/configure.ac @@ -2698,8 +2698,6 @@ AC_CHECK_FUNCS(\ expm1f \ fma \ fmaf \ - ilogb \ - ilogbf \ j0 \ j1 \ jn \ diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index f5e933fc188..6763b4a00dd 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -4402,32 +4402,53 @@ double CDECL MSVCR120_creal(_Dcomplex z) return z.x; } +/********************************************************************* + * ilogb (MSVCR120.@) + * + * Copied from musl: src/math/ilogb.c + */ int CDECL MSVCR120_ilogb(double x) { - if (!x) return MSVCRT_FP_ILOGB0; - if (isnan(x)) return MSVCRT_FP_ILOGBNAN; - if (isinf(x)) return MSVCRT_INT_MAX; + union { double f; UINT64 i; } u = { x }; + int e = u.i >> 52 & 0x7ff; -#ifdef HAVE_ILOGB - return ilogb(x); -#else - return logb(x); -#endif + if (!e) + { + u.i <<= 12; + if (u.i == 0) return MSVCRT_FP_ILOGB0; + /* subnormal x */ + for (e = -0x3ff; u.i >> 63 == 0; e--, u.i <<= 1); + return e; + } + if (e == 0x7ff) return u.i << 12 ? MSVCRT_FP_ILOGBNAN : MSVCRT_INT_MAX; + return e - 0x3ff; } +/********************************************************************* + * ilogbf (MSVCR120.@) + * + * Copied from musl: src/math/ilogbf.c + */ int CDECL MSVCR120_ilogbf(float x) { - if (!x) return MSVCRT_FP_ILOGB0; - if (isnan(x)) return MSVCRT_FP_ILOGBNAN; - if (isinf(x)) return MSVCRT_INT_MAX; + union { float f; UINT32 i; } u = { x }; + int e = u.i >> 23 & 0xff; -#ifdef HAVE_ILOGBF - return ilogbf(x); -#else - return logbf(x); -#endif + if (!e) + { + u.i <<= 9; + if (u.i == 0) return MSVCRT_FP_ILOGB0; + /* subnormal x */ + for (e = -0x7f; u.i >> 31 == 0; e--, u.i <<= 1); + return e; + } + if (e == 0xff) return u.i << 9 ? MSVCRT_FP_ILOGBNAN : MSVCRT_INT_MAX; + return e - 0x7f; } +/********************************************************************* + * ilogbl (MSVCR120.@) + */ int CDECL MSVCR120_ilogbl(LDOUBLE x) { return MSVCR120_ilogb(x); diff --git a/include/config.h.in b/include/config.h.in index 241fa7ede38..cd13b9d4bee 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -288,12 +288,6 @@ /* Define to 1 if you have the `if_nameindex' function. */ #undef HAVE_IF_NAMEINDEX -/* Define to 1 if you have the `ilogb' function. */ -#undef HAVE_ILOGB - -/* Define to 1 if you have the `ilogbf' function. */ -#undef HAVE_ILOGBF - /* Define to 1 if you have the header file. */ #undef HAVE_INET_MIB2_H