2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll math functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2020-08-04 15:17:04 +02:00
|
|
|
*
|
|
|
|
*
|
2020-11-17 13:45:45 +01:00
|
|
|
* For functions copied from musl libc (http://musl.libc.org/):
|
2020-08-04 15:17:04 +02:00
|
|
|
* ====================================================
|
2020-11-17 13:45:45 +01:00
|
|
|
* Copyright 2005-2020 Rich Felker, et al.
|
2020-08-04 15:17:04 +02:00
|
|
|
*
|
2020-11-17 13:45:45 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2020-08-04 15:17:04 +02:00
|
|
|
* ====================================================
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2020-08-04 15:17:04 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2003-03-21 00:47:25 +01:00
|
|
|
#include <stdio.h>
|
2020-11-20 12:51:23 +01:00
|
|
|
#include <fenv.h>
|
2020-11-20 12:44:42 +01:00
|
|
|
#include <fpieee.h>
|
2020-11-27 14:17:01 +01:00
|
|
|
#include <limits.h>
|
2020-11-26 19:19:05 +01:00
|
|
|
#include <locale.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2004-03-16 20:17:11 +01:00
|
|
|
#include "msvcrt.h"
|
2020-11-18 16:14:50 +01:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "unixlib.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2017-08-02 07:51:36 +02:00
|
|
|
#define _DOMAIN 1 /* domain error in argument */
|
|
|
|
#define _SING 2 /* singularity */
|
|
|
|
#define _OVERFLOW 3 /* range overflow */
|
|
|
|
#define _UNDERFLOW 4 /* range underflow */
|
|
|
|
|
2020-11-30 14:37:39 +01:00
|
|
|
typedef int (CDECL *MSVCRT_matherr_func)(struct _exception *);
|
2014-12-08 13:35:25 +01:00
|
|
|
typedef double LDOUBLE; /* long double is just a double */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
|
|
|
|
|
2011-01-25 21:01:12 +01:00
|
|
|
static BOOL sse2_supported;
|
|
|
|
static BOOL sse2_enabled;
|
|
|
|
|
2020-11-18 16:14:50 +01:00
|
|
|
static const struct unix_funcs *unix_funcs;
|
|
|
|
|
|
|
|
void msvcrt_init_math( void *module )
|
2011-01-25 21:01:12 +01:00
|
|
|
{
|
|
|
|
sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
|
2020-11-18 16:14:50 +01:00
|
|
|
__wine_init_unix_lib( module, DLL_PROCESS_ATTACH, NULL, &unix_funcs );
|
2011-01-25 21:01:12 +01:00
|
|
|
}
|
|
|
|
|
2020-08-06 16:59:33 +02:00
|
|
|
/* Copied from musl: src/internal/libm.h */
|
|
|
|
static inline float fp_barrierf(float x)
|
|
|
|
{
|
|
|
|
volatile float y = x;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2017-08-02 07:51:36 +02:00
|
|
|
/*********************************************************************
|
2019-04-05 09:27:37 +02:00
|
|
|
* _matherr (CRTDLL.@)
|
2017-08-02 07:51:36 +02:00
|
|
|
*/
|
2020-11-30 14:37:39 +01:00
|
|
|
int CDECL MSVCRT__matherr(struct _exception *e)
|
2017-08-02 07:51:36 +02:00
|
|
|
{
|
2019-04-05 09:27:37 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-08-02 07:51:36 +02:00
|
|
|
|
2019-04-05 09:27:37 +02:00
|
|
|
|
2020-08-04 15:16:49 +02:00
|
|
|
static double math_error(int type, const char *name, double arg1, double arg2, double retval)
|
2019-04-05 09:27:37 +02:00
|
|
|
{
|
2020-11-30 14:37:39 +01:00
|
|
|
struct _exception exception = {type, (char *)name, arg1, arg2, retval};
|
2020-08-04 15:16:49 +02:00
|
|
|
|
2019-04-05 09:27:37 +02:00
|
|
|
TRACE("(%d, %s, %g, %g, %g)\n", type, debugstr_a(name), arg1, arg2, retval);
|
2017-08-02 07:51:36 +02:00
|
|
|
|
2020-08-04 15:16:49 +02:00
|
|
|
if (MSVCRT_default_matherr_func && MSVCRT_default_matherr_func(&exception))
|
|
|
|
return exception.retval;
|
2017-08-02 07:51:36 +02:00
|
|
|
|
2019-04-05 09:27:37 +02:00
|
|
|
switch (type)
|
2017-08-02 07:51:36 +02:00
|
|
|
{
|
|
|
|
case _DOMAIN:
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2017-08-02 07:51:36 +02:00
|
|
|
break;
|
|
|
|
case _SING:
|
|
|
|
case _OVERFLOW:
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
2017-08-02 07:51:36 +02:00
|
|
|
break;
|
|
|
|
case _UNDERFLOW:
|
|
|
|
/* don't set errno */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unhandled math error!\n");
|
|
|
|
}
|
2020-08-04 15:16:49 +02:00
|
|
|
|
|
|
|
return exception.retval;
|
2017-08-02 07:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __setusermatherr (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
|
|
|
|
{
|
|
|
|
MSVCRT_default_matherr_func = func;
|
|
|
|
TRACE("new matherr handler %p\n", func);
|
|
|
|
}
|
|
|
|
|
2010-08-25 14:46:05 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_SSE2_enable (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__set_SSE2_enable(int flag)
|
|
|
|
{
|
2011-01-25 21:01:12 +01:00
|
|
|
sse2_enabled = flag && sse2_supported;
|
|
|
|
return sse2_enabled;
|
2010-08-25 14:46:05 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 13:06:21 +01:00
|
|
|
#if defined(_WIN64)
|
|
|
|
# if _MSVCR_VER>=140
|
|
|
|
/*********************************************************************
|
|
|
|
* _get_FMA3_enable (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__get_FMA3_enable(void)
|
|
|
|
{
|
|
|
|
FIXME("() stub\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if _MSVCR_VER>=120
|
2016-01-18 21:08:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_FMA3_enable (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__set_FMA3_enable(int flag)
|
|
|
|
{
|
|
|
|
FIXME("(%x) stub\n", flag);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-11 13:06:21 +01:00
|
|
|
# endif
|
2016-01-18 21:08:29 +01:00
|
|
|
#endif
|
|
|
|
|
2019-10-16 14:34:19 +02:00
|
|
|
#if !defined(__i386__) || _MSVCR_VER>=120
|
2010-05-01 16:32:19 +02:00
|
|
|
|
2012-08-16 18:03:27 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _chgsignf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT__chgsignf( float num )
|
|
|
|
{
|
2020-11-16 15:04:00 +01:00
|
|
|
union { float f; UINT32 i; } u = { num };
|
|
|
|
u.i ^= 0x80000000;
|
|
|
|
return u.f;
|
2012-08-16 18:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _copysignf (MSVCRT.@)
|
2020-11-17 09:57:52 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/copysignf.c
|
2012-08-16 18:03:27 +02:00
|
|
|
*/
|
2020-11-17 09:57:52 +01:00
|
|
|
float CDECL MSVCRT__copysignf( float x, float y )
|
2012-08-16 18:03:27 +02:00
|
|
|
{
|
2020-11-17 09:57:52 +01:00
|
|
|
union { float f; UINT32 i; } ux = { x }, uy = { y };
|
|
|
|
ux.i &= 0x7fffffff;
|
|
|
|
ux.i |= uy.i & 0x80000000;
|
|
|
|
return ux.f;
|
2012-08-16 18:03:27 +02:00
|
|
|
}
|
|
|
|
|
2015-12-28 13:48:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _nextafterf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT__nextafterf( float num, float next )
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->nextafterf( num, next );
|
2015-12-28 13:48:23 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 12:46:57 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _logbf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT__logbf( float num )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->logbf(num);
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(num)) return math_error(_DOMAIN, "_logbf", num, 0, ret);
|
|
|
|
if (!num) return math_error(_SING, "_logbf", num, 0, ret);
|
2019-04-23 12:46:57 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:31:38 +02:00
|
|
|
#endif
|
2019-10-16 14:34:19 +02:00
|
|
|
|
2020-11-16 12:10:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _fpclassf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__fpclassf( float num )
|
|
|
|
{
|
|
|
|
union { float f; UINT32 i; } u = { num };
|
|
|
|
int e = u.i >> 23 & 0xff;
|
|
|
|
int s = u.i >> 31;
|
|
|
|
|
|
|
|
switch (e)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (u.i << 1) return s ? MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
|
|
|
|
return s ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
|
|
|
|
case 0xff:
|
|
|
|
if (u.i << 9) return ((u.i >> 22) & 1) ? MSVCRT__FPCLASS_QNAN : MSVCRT__FPCLASS_SNAN;
|
|
|
|
return s ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
|
|
|
|
default:
|
|
|
|
return s ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 18:03:27 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _finitef (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__finitef( float num )
|
|
|
|
{
|
2020-11-16 12:17:52 +01:00
|
|
|
union { float f; UINT32 i; } u = { num };
|
|
|
|
return (u.i & 0x7fffffff) < 0x7f800000;
|
2012-08-16 18:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _isnanf (MSVCRT.@)
|
|
|
|
*/
|
2020-11-16 12:18:03 +01:00
|
|
|
int CDECL MSVCRT__isnanf( float num )
|
2012-08-16 18:03:27 +02:00
|
|
|
{
|
2020-11-16 12:18:03 +01:00
|
|
|
union { float f; UINT32 i; } u = { num };
|
|
|
|
return (u.i & 0x7fffffff) > 0x7f800000;
|
2012-08-16 18:03:27 +02:00
|
|
|
}
|
|
|
|
|
2010-05-01 16:32:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_acosf (MSVCRT.@)
|
2020-08-05 17:11:20 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/acosf.c
|
2010-05-01 16:32:19 +02:00
|
|
|
*/
|
2020-08-05 17:11:20 +02:00
|
|
|
static float acosf_R(float z)
|
|
|
|
{
|
|
|
|
static const float pS0 = 1.6666586697e-01,
|
|
|
|
pS1 = -4.2743422091e-02,
|
|
|
|
pS2 = -8.6563630030e-03,
|
|
|
|
qS1 = -7.0662963390e-01;
|
|
|
|
|
|
|
|
float p, q;
|
|
|
|
p = z * (pS0 + z * (pS1 + z * pS2));
|
|
|
|
q = 1.0f + z * qS1;
|
|
|
|
return p / q;
|
|
|
|
}
|
|
|
|
|
2010-05-01 16:32:19 +02:00
|
|
|
float CDECL MSVCRT_acosf( float x )
|
|
|
|
{
|
2020-08-05 17:11:20 +02:00
|
|
|
static const float pio2_hi = 1.5707962513e+00,
|
|
|
|
pio2_lo = 7.5497894159e-08;
|
|
|
|
|
|
|
|
float z, w, s, c, df;
|
|
|
|
unsigned int hx, ix;
|
|
|
|
|
|
|
|
hx = *(unsigned int*)&x;
|
|
|
|
ix = hx & 0x7fffffff;
|
|
|
|
/* |x| >= 1 or nan */
|
|
|
|
if (ix >= 0x3f800000) {
|
|
|
|
if (ix == 0x3f800000) {
|
|
|
|
if (hx >> 31)
|
2020-08-18 18:19:50 +02:00
|
|
|
return 2 * pio2_lo + 2 * pio2_hi + 7.5231638453e-37;
|
2020-08-05 17:11:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isnan(x)) return x;
|
2020-08-05 17:11:20 +02:00
|
|
|
return math_error(_DOMAIN, "acosf", x, 0, 0 / (x - x));
|
|
|
|
}
|
|
|
|
/* |x| < 0.5 */
|
|
|
|
if (ix < 0x3f000000) {
|
|
|
|
if (ix <= 0x32800000) /* |x| < 2**-26 */
|
2020-08-18 18:19:50 +02:00
|
|
|
return pio2_lo + pio2_hi + 7.5231638453e-37;
|
2020-08-05 17:11:20 +02:00
|
|
|
return pio2_hi - (x - (pio2_lo - x * acosf_R(x * x)));
|
|
|
|
}
|
|
|
|
/* x < -0.5 */
|
|
|
|
if (hx >> 31) {
|
|
|
|
z = (1 + x) * 0.5f;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrtf(z);
|
2020-08-05 17:11:20 +02:00
|
|
|
w = acosf_R(z) * s - pio2_lo;
|
|
|
|
return 2 * (pio2_hi - (s + w));
|
|
|
|
}
|
|
|
|
/* x > 0.5 */
|
|
|
|
z = (1 - x) * 0.5f;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrtf(z);
|
2020-08-05 17:11:20 +02:00
|
|
|
hx = *(unsigned int*)&s & 0xfffff000;
|
|
|
|
df = *(float*)&hx;
|
|
|
|
c = (z - df * df) / (s + df);
|
|
|
|
w = acosf_R(z) * s + c;
|
|
|
|
return 2 * (df + w);
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_asinf (MSVCRT.@)
|
2020-08-06 16:59:14 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/asinf.c
|
2010-05-01 16:32:19 +02:00
|
|
|
*/
|
2020-08-06 16:59:14 +02:00
|
|
|
static float asinf_R(float z)
|
|
|
|
{
|
|
|
|
/* coefficients for R(x^2) */
|
|
|
|
static const float pS0 = 1.6666586697e-01,
|
|
|
|
pS1 = -4.2743422091e-02,
|
|
|
|
pS2 = -8.6563630030e-03,
|
|
|
|
qS1 = -7.0662963390e-01;
|
|
|
|
|
2020-11-19 13:28:52 +01:00
|
|
|
float p, q;
|
2020-08-06 16:59:14 +02:00
|
|
|
p = z * (pS0 + z * (pS1 + z * pS2));
|
|
|
|
q = 1.0f + z * qS1;
|
|
|
|
return p / q;
|
|
|
|
}
|
|
|
|
|
2010-05-01 16:32:19 +02:00
|
|
|
float CDECL MSVCRT_asinf( float x )
|
|
|
|
{
|
2020-08-06 16:59:14 +02:00
|
|
|
static const double pio2 = 1.570796326794896558e+00;
|
|
|
|
|
|
|
|
double s;
|
|
|
|
float z;
|
|
|
|
unsigned int hx, ix;
|
|
|
|
|
|
|
|
hx = *(unsigned int*)&x;
|
|
|
|
ix = hx & 0x7fffffff;
|
|
|
|
if (ix >= 0x3f800000) { /* |x| >= 1 */
|
|
|
|
if (ix == 0x3f800000) /* |x| == 1 */
|
|
|
|
return x * pio2 + 7.5231638453e-37; /* asin(+-1) = +-pi/2 with inexact */
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isnan(x)) return x;
|
2020-08-06 16:59:14 +02:00
|
|
|
return math_error(_DOMAIN, "asinf", x, 0, 0 / (x - x));
|
|
|
|
}
|
|
|
|
if (ix < 0x3f000000) { /* |x| < 0.5 */
|
|
|
|
/* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
|
|
|
|
if (ix < 0x39800000 && ix >= 0x00800000)
|
|
|
|
return x;
|
|
|
|
return x + x * asinf_R(x * x);
|
|
|
|
}
|
|
|
|
/* 1 > |x| >= 0.5 */
|
|
|
|
z = (1 - fabsf(x)) * 0.5f;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrt(z);
|
2020-08-06 16:59:14 +02:00
|
|
|
x = pio2 - 2 * (s + s * asinf_R(z));
|
|
|
|
if (hx >> 31)
|
|
|
|
return -x;
|
|
|
|
return x;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_atanf (MSVCRT.@)
|
2020-08-06 16:59:29 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/atanf.c
|
2010-05-01 16:32:19 +02:00
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_atanf( float x )
|
|
|
|
{
|
2020-08-06 16:59:29 +02:00
|
|
|
static const float atanhi[] = {
|
|
|
|
4.6364760399e-01,
|
|
|
|
7.8539812565e-01,
|
|
|
|
9.8279368877e-01,
|
|
|
|
1.5707962513e+00,
|
|
|
|
};
|
|
|
|
static const float atanlo[] = {
|
|
|
|
5.0121582440e-09,
|
|
|
|
3.7748947079e-08,
|
|
|
|
3.4473217170e-08,
|
|
|
|
7.5497894159e-08,
|
|
|
|
};
|
|
|
|
static const float aT[] = {
|
|
|
|
3.3333328366e-01,
|
|
|
|
-1.9999158382e-01,
|
|
|
|
1.4253635705e-01,
|
|
|
|
-1.0648017377e-01,
|
|
|
|
6.1687607318e-02,
|
|
|
|
};
|
|
|
|
|
|
|
|
float w, s1, s2, z;
|
|
|
|
unsigned int ix, sign;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
#if _MSVCR_VER == 0
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "atanf", x, 0, x);
|
2020-08-06 16:59:29 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ix = *(unsigned int*)&x;
|
|
|
|
sign = ix >> 31;
|
|
|
|
ix &= 0x7fffffff;
|
|
|
|
if (ix >= 0x4c800000) { /* if |x| >= 2**26 */
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isnan(x))
|
2020-08-06 16:59:29 +02:00
|
|
|
return x;
|
|
|
|
z = atanhi[3] + 7.5231638453e-37;
|
|
|
|
return sign ? -z : z;
|
|
|
|
}
|
|
|
|
if (ix < 0x3ee00000) { /* |x| < 0.4375 */
|
|
|
|
if (ix < 0x39800000) { /* |x| < 2**-12 */
|
|
|
|
if (ix < 0x00800000)
|
|
|
|
/* raise underflow for subnormal x */
|
|
|
|
fp_barrierf(x*x);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
id = -1;
|
|
|
|
} else {
|
|
|
|
x = fabsf(x);
|
|
|
|
if (ix < 0x3f980000) { /* |x| < 1.1875 */
|
|
|
|
if (ix < 0x3f300000) { /* 7/16 <= |x| < 11/16 */
|
|
|
|
id = 0;
|
|
|
|
x = (2.0f * x - 1.0f) / (2.0f + x);
|
|
|
|
} else { /* 11/16 <= |x| < 19/16 */
|
|
|
|
id = 1;
|
|
|
|
x = (x - 1.0f) / (x + 1.0f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ix < 0x401c0000) { /* |x| < 2.4375 */
|
|
|
|
id = 2;
|
|
|
|
x = (x - 1.5f) / (1.0f + 1.5f * x);
|
|
|
|
} else { /* 2.4375 <= |x| < 2**26 */
|
|
|
|
id = 3;
|
|
|
|
x = -1.0f / x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* end of argument reduction */
|
|
|
|
z = x * x;
|
|
|
|
w = z * z;
|
|
|
|
/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
|
|
|
|
s1 = z * (aT[0] + w * (aT[2] + w * aT[4]));
|
|
|
|
s2 = w * (aT[1] + w * aT[3]);
|
|
|
|
if (id < 0)
|
|
|
|
return x - x * (s1 + s2);
|
|
|
|
z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x);
|
|
|
|
return sign ? -z : z;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_atan2f (MSVCRT.@)
|
2020-08-06 16:59:21 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/atan2f.c
|
2010-05-01 16:32:19 +02:00
|
|
|
*/
|
2020-08-06 16:59:21 +02:00
|
|
|
float CDECL MSVCRT_atan2f( float y, float x )
|
2010-05-01 16:32:19 +02:00
|
|
|
{
|
2020-08-06 16:59:21 +02:00
|
|
|
static const float pi = 3.1415927410e+00,
|
|
|
|
pi_lo = -8.7422776573e-08;
|
|
|
|
|
|
|
|
float z;
|
|
|
|
unsigned int m, ix, iy;
|
|
|
|
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isnan(x) || isnan(y))
|
2020-08-06 16:59:21 +02:00
|
|
|
return x + y;
|
|
|
|
ix = *(unsigned int*)&x;
|
|
|
|
iy = *(unsigned int*)&y;
|
|
|
|
if (ix == 0x3f800000) /* x=1.0 */
|
2020-11-18 16:01:52 +01:00
|
|
|
return MSVCRT_atanf(y);
|
2020-08-06 16:59:21 +02:00
|
|
|
m = ((iy >> 31) & 1) | ((ix >> 30) & 2); /* 2*sign(x)+sign(y) */
|
|
|
|
ix &= 0x7fffffff;
|
|
|
|
iy &= 0x7fffffff;
|
|
|
|
|
|
|
|
/* when y = 0 */
|
|
|
|
if (iy == 0) {
|
|
|
|
switch (m) {
|
|
|
|
case 0:
|
|
|
|
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
|
|
|
case 2: return pi; /* atan(+0,-anything) = pi */
|
|
|
|
case 3: return -pi; /* atan(-0,-anything) =-pi */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* when x = 0 */
|
|
|
|
if (ix == 0)
|
|
|
|
return m & 1 ? -pi / 2 : pi / 2;
|
|
|
|
/* when x is INF */
|
|
|
|
if (ix == 0x7f800000) {
|
|
|
|
if (iy == 0x7f800000) {
|
|
|
|
switch (m) {
|
|
|
|
case 0: return pi / 4; /* atan(+INF,+INF) */
|
|
|
|
case 1: return -pi / 4; /* atan(-INF,+INF) */
|
|
|
|
case 2: return 3 * pi / 4; /*atan(+INF,-INF)*/
|
|
|
|
case 3: return -3 * pi / 4; /*atan(-INF,-INF)*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (m) {
|
|
|
|
case 0: return 0.0f; /* atan(+...,+INF) */
|
|
|
|
case 1: return -0.0f; /* atan(-...,+INF) */
|
|
|
|
case 2: return pi; /* atan(+...,-INF) */
|
|
|
|
case 3: return -pi; /* atan(-...,-INF) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* |y/x| > 0x1p26 */
|
|
|
|
if (ix + (26 << 23) < iy || iy == 0x7f800000)
|
|
|
|
return m & 1 ? -pi / 2 : pi / 2;
|
|
|
|
|
|
|
|
/* z = atan(|y/x|) with correct underflow */
|
|
|
|
if ((m & 2) && iy + (26 << 23) < ix) /*|y/x| < 0x1p-26, x < 0 */
|
|
|
|
z = 0.0;
|
|
|
|
else
|
2020-11-18 16:01:52 +01:00
|
|
|
z = MSVCRT_atanf(fabsf(y / x));
|
2020-08-06 16:59:21 +02:00
|
|
|
switch (m) {
|
|
|
|
case 0: return z; /* atan(+,+) */
|
|
|
|
case 1: return -z; /* atan(-,+) */
|
|
|
|
case 2: return pi - (z - pi_lo); /* atan(+,-) */
|
|
|
|
default: /* case 3 */
|
|
|
|
return (z - pi_lo) - pi; /* atan(-,-) */
|
|
|
|
}
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_cosf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_cosf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->cosf( x );
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "cosf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_coshf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_coshf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->coshf( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "coshf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_expf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_expf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->expf( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "expf", x, 0, ret);
|
2020-11-17 10:12:34 +01:00
|
|
|
if (isfinite(x) && !ret) return math_error(_UNDERFLOW, "expf", x, 0, ret);
|
|
|
|
if (isfinite(x) && !isfinite(ret)) return math_error(_OVERFLOW, "expf", x, 0, ret);
|
2017-07-25 08:52:27 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_fmodf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_fmodf( float x, float y )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->fmodf( x, y );
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!isfinite(x) || !isfinite(y)) return math_error(_DOMAIN, "fmodf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_logf (MSVCRT.@)
|
|
|
|
*/
|
2017-07-18 06:33:53 +02:00
|
|
|
float CDECL MSVCRT_logf( float x )
|
2010-05-01 16:32:19 +02:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->logf( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (x < 0.0) return math_error(_DOMAIN, "logf", x, 0, ret);
|
|
|
|
if (x == 0.0) return math_error(_SING, "logf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_log10f (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_log10f( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->log10f( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (x < 0.0) return math_error(_DOMAIN, "log10f", x, 0, ret);
|
|
|
|
if (x == 0.0) return math_error(_SING, "log10f", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_powf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_powf( float x, float y )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float z = unix_funcs->powf(x,y);
|
2020-11-18 16:01:52 +01:00
|
|
|
if (x < 0 && y != MSVCRT_floorf(y)) return math_error(_DOMAIN, "powf", x, y, z);
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!x && isfinite(y) && y < 0) return math_error(_SING, "powf", x, y, z);
|
|
|
|
if (isfinite(x) && isfinite(y) && !isfinite(z)) return math_error(_OVERFLOW, "powf", x, y, z);
|
|
|
|
if (x && isfinite(x) && isfinite(y) && !z) return math_error(_UNDERFLOW, "powf", x, y, z);
|
2010-05-01 16:32:19 +02:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sinf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_sinf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->sinf( x );
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "sinf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sinhf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_sinhf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->sinhf( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "sinhf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sqrtf (MSVCRT.@)
|
2020-08-04 15:17:04 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/sqrtf.c
|
2010-05-01 16:32:19 +02:00
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_sqrtf( float x )
|
|
|
|
{
|
2020-08-04 15:17:04 +02:00
|
|
|
static const float tiny = 1.0e-30;
|
|
|
|
|
|
|
|
float z;
|
|
|
|
int sign = 0x80000000;
|
|
|
|
int ix,s,q,m,t,i;
|
|
|
|
unsigned int r;
|
|
|
|
|
|
|
|
ix = *(int*)&x;
|
|
|
|
|
|
|
|
/* take care of Inf and NaN */
|
|
|
|
if ((ix & 0x7f800000) == 0x7f800000 && (ix == 0x7f800000 || ix & 0x7fffff))
|
|
|
|
return x;
|
|
|
|
|
|
|
|
/* take care of zero */
|
|
|
|
if (ix <= 0) {
|
|
|
|
if ((ix & ~sign) == 0)
|
|
|
|
return x; /* sqrt(+-0) = +-0 */
|
|
|
|
return math_error(_DOMAIN, "sqrtf", x, 0, (x - x) / (x - x)); /* sqrt(-ve) = sNaN */
|
|
|
|
}
|
|
|
|
/* normalize x */
|
|
|
|
m = ix >> 23;
|
|
|
|
if (m == 0) { /* subnormal x */
|
|
|
|
for (i = 0; (ix & 0x00800000) == 0; i++)
|
|
|
|
ix <<= 1;
|
|
|
|
m -= i - 1;
|
|
|
|
}
|
|
|
|
m -= 127; /* unbias exponent */
|
|
|
|
ix = (ix & 0x007fffff) | 0x00800000;
|
|
|
|
if (m & 1) /* odd m, double x to make it even */
|
|
|
|
ix += ix;
|
|
|
|
m >>= 1; /* m = [m/2] */
|
|
|
|
|
|
|
|
/* generate sqrt(x) bit by bit */
|
|
|
|
ix += ix;
|
|
|
|
q = s = 0; /* q = sqrt(x) */
|
|
|
|
r = 0x01000000; /* r = moving bit from right to left */
|
|
|
|
|
|
|
|
while (r != 0) {
|
|
|
|
t = s + r;
|
|
|
|
if (t <= ix) {
|
|
|
|
s = t + r;
|
|
|
|
ix -= t;
|
|
|
|
q += r;
|
|
|
|
}
|
|
|
|
ix += ix;
|
|
|
|
r >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use floating add to find out rounding direction */
|
|
|
|
if (ix != 0) {
|
|
|
|
z = 1.0f - tiny; /* raise inexact flag */
|
|
|
|
if (z >= 1.0f) {
|
|
|
|
z = 1.0f + tiny;
|
|
|
|
if (z > 1.0f)
|
|
|
|
q += 2;
|
|
|
|
else
|
|
|
|
q += q & 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ix = (q >> 1) + 0x3f000000;
|
|
|
|
r = ix + ((unsigned int)m << 23);
|
|
|
|
z = *(float*)&r;
|
|
|
|
return z;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_tanf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_tanf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->tanf(x);
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "tanf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_tanhf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_tanhf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->tanhf(x);
|
2020-11-17 10:12:34 +01:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "tanhf", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ceilf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_ceilf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->ceilf(x);
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:24:27 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fabsf (MSVCRT.@)
|
2020-11-17 09:58:19 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/fabsf.c
|
2013-09-03 21:24:27 +02:00
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_fabsf( float x )
|
|
|
|
{
|
2020-11-17 09:58:19 +01:00
|
|
|
union { float f; UINT32 i; } u = { x };
|
|
|
|
u.i &= 0x7fffffff;
|
|
|
|
return u.f;
|
2013-09-03 21:24:27 +02:00
|
|
|
}
|
|
|
|
|
2010-05-01 16:32:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* floorf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_floorf( float x )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->floorf(x);
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* frexpf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_frexpf( float x, int *exp )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->frexpf( x, exp );
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* modff (MSVCRT.@)
|
|
|
|
*/
|
2016-01-15 17:01:02 +01:00
|
|
|
float CDECL MSVCRT_modff( float x, float *iptr )
|
2010-05-01 16:32:19 +02:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->modff( x, iptr );
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:36:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_acos (MSVCRT.@)
|
2020-08-05 17:11:36 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/acos.c
|
2006-01-14 17:36:23 +01:00
|
|
|
*/
|
2020-08-05 17:11:36 +02:00
|
|
|
static double acos_R(double z)
|
|
|
|
{
|
|
|
|
static const double pS0 = 1.66666666666666657415e-01,
|
|
|
|
pS1 = -3.25565818622400915405e-01,
|
|
|
|
pS2 = 2.01212532134862925881e-01,
|
|
|
|
pS3 = -4.00555345006794114027e-02,
|
|
|
|
pS4 = 7.91534994289814532176e-04,
|
|
|
|
pS5 = 3.47933107596021167570e-05,
|
|
|
|
qS1 = -2.40339491173441421878e+00,
|
|
|
|
qS2 = 2.02094576023350569471e+00,
|
|
|
|
qS3 = -6.88283971605453293030e-01,
|
|
|
|
qS4 = 7.70381505559019352791e-02;
|
|
|
|
|
|
|
|
double p, q;
|
|
|
|
p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
|
|
|
|
q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
|
|
|
|
return p/q;
|
|
|
|
}
|
|
|
|
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_acos( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-08-05 17:11:36 +02:00
|
|
|
static const double pio2_hi = 1.57079632679489655800e+00,
|
|
|
|
pio2_lo = 6.12323399573676603587e-17;
|
|
|
|
|
|
|
|
double z, w, s, c, df;
|
|
|
|
unsigned int hx, ix;
|
|
|
|
ULONGLONG llx;
|
|
|
|
|
|
|
|
hx = *(ULONGLONG*)&x >> 32;
|
|
|
|
ix = hx & 0x7fffffff;
|
|
|
|
/* |x| >= 1 or nan */
|
|
|
|
if (ix >= 0x3ff00000) {
|
|
|
|
unsigned int lx;
|
|
|
|
|
|
|
|
lx = *(ULONGLONG*)&x;
|
|
|
|
if (((ix - 0x3ff00000) | lx) == 0) {
|
|
|
|
/* acos(1)=0, acos(-1)=pi */
|
|
|
|
if (hx >> 31)
|
|
|
|
return 2 * pio2_hi + 7.5231638452626401e-37;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (isnan(x)) return x;
|
|
|
|
return math_error(_DOMAIN, "acos", x, 0, 0 / (x - x));
|
|
|
|
}
|
|
|
|
/* |x| < 0.5 */
|
|
|
|
if (ix < 0x3fe00000) {
|
|
|
|
if (ix <= 0x3c600000) /* |x| < 2**-57 */
|
|
|
|
return pio2_hi + 7.5231638452626401e-37;
|
|
|
|
return pio2_hi - (x - (pio2_lo - x * acos_R(x * x)));
|
|
|
|
}
|
|
|
|
/* x < -0.5 */
|
|
|
|
if (hx >> 31) {
|
|
|
|
z = (1.0 + x) * 0.5;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrt(z);
|
2020-08-05 17:11:36 +02:00
|
|
|
w = acos_R(z) * s - pio2_lo;
|
|
|
|
return 2 * (pio2_hi - (s + w));
|
|
|
|
}
|
|
|
|
/* x > 0.5 */
|
|
|
|
z = (1.0 - x) * 0.5;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrt(z);
|
2020-08-05 17:11:36 +02:00
|
|
|
df = s;
|
|
|
|
llx = (*(ULONGLONG*)&df >> 32) << 32;
|
|
|
|
df = *(double*)&llx;
|
|
|
|
c = (z - df * df) / (s + df);
|
|
|
|
w = acos_R(z) * s + c;
|
|
|
|
return 2 * (df + w);
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_asin (MSVCRT.@)
|
2020-08-06 16:59:17 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/asin.c
|
2006-01-14 17:36:23 +01:00
|
|
|
*/
|
2020-08-06 16:59:17 +02:00
|
|
|
static double asin_R(double z)
|
|
|
|
{
|
|
|
|
/* coefficients for R(x^2) */
|
|
|
|
static const double pS0 = 1.66666666666666657415e-01,
|
|
|
|
pS1 = -3.25565818622400915405e-01,
|
|
|
|
pS2 = 2.01212532134862925881e-01,
|
|
|
|
pS3 = -4.00555345006794114027e-02,
|
|
|
|
pS4 = 7.91534994289814532176e-04,
|
|
|
|
pS5 = 3.47933107596021167570e-05,
|
|
|
|
qS1 = -2.40339491173441421878e+00,
|
|
|
|
qS2 = 2.02094576023350569471e+00,
|
|
|
|
qS3 = -6.88283971605453293030e-01,
|
|
|
|
qS4 = 7.70381505559019352791e-02;
|
|
|
|
|
|
|
|
double p, q;
|
|
|
|
p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
|
|
|
|
q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
|
|
|
|
return p / q;
|
|
|
|
}
|
|
|
|
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_asin( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-08-06 16:59:17 +02:00
|
|
|
static const double pio2_hi = 1.57079632679489655800e+00,
|
|
|
|
pio2_lo = 6.12323399573676603587e-17;
|
|
|
|
|
|
|
|
double z, r, s;
|
|
|
|
unsigned int hx, ix;
|
|
|
|
ULONGLONG llx;
|
|
|
|
|
|
|
|
hx = *(ULONGLONG*)&x >> 32;
|
|
|
|
ix = hx & 0x7fffffff;
|
|
|
|
/* |x| >= 1 or nan */
|
|
|
|
if (ix >= 0x3ff00000) {
|
|
|
|
unsigned int lx;
|
|
|
|
lx = *(ULONGLONG*)&x;
|
|
|
|
if (((ix - 0x3ff00000) | lx) == 0)
|
|
|
|
/* asin(1) = +-pi/2 with inexact */
|
|
|
|
return x * pio2_hi + 7.5231638452626401e-37;
|
|
|
|
if (isnan(x)) return x;
|
|
|
|
return math_error(_DOMAIN, "asin", x, 0, 0 / (x - x));
|
|
|
|
}
|
|
|
|
/* |x| < 0.5 */
|
|
|
|
if (ix < 0x3fe00000) {
|
|
|
|
/* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
|
|
|
|
if (ix < 0x3e500000 && ix >= 0x00100000)
|
|
|
|
return x;
|
|
|
|
return x + x * asin_R(x * x);
|
|
|
|
}
|
|
|
|
/* 1 > |x| >= 0.5 */
|
|
|
|
z = (1 - fabs(x)) * 0.5;
|
2020-11-18 16:01:52 +01:00
|
|
|
s = MSVCRT_sqrt(z);
|
2020-08-06 16:59:17 +02:00
|
|
|
r = asin_R(z);
|
|
|
|
if (ix >= 0x3fef3333) { /* if |x| > 0.975 */
|
|
|
|
x = pio2_hi - (2 * (s + s * r) - pio2_lo);
|
|
|
|
} else {
|
|
|
|
double f, c;
|
|
|
|
/* f+c = sqrt(z) */
|
|
|
|
f = s;
|
|
|
|
llx = (*(ULONGLONG*)&f >> 32) << 32;
|
|
|
|
f = *(double*)&llx;
|
|
|
|
c = (z - f * f) / (s + f);
|
|
|
|
x = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * f));
|
|
|
|
}
|
|
|
|
if (hx >> 31)
|
|
|
|
return -x;
|
|
|
|
return x;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_atan (MSVCRT.@)
|
2020-08-06 16:59:33 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/atan.c
|
2006-01-14 17:36:23 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_atan( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-08-06 16:59:33 +02:00
|
|
|
static const double atanhi[] = {
|
|
|
|
4.63647609000806093515e-01,
|
|
|
|
7.85398163397448278999e-01,
|
|
|
|
9.82793723247329054082e-01,
|
|
|
|
1.57079632679489655800e+00,
|
|
|
|
};
|
|
|
|
static const double atanlo[] = {
|
|
|
|
2.26987774529616870924e-17,
|
|
|
|
3.06161699786838301793e-17,
|
|
|
|
1.39033110312309984516e-17,
|
|
|
|
6.12323399573676603587e-17,
|
|
|
|
};
|
|
|
|
static const double aT[] = {
|
|
|
|
3.33333333333329318027e-01,
|
|
|
|
-1.99999999998764832476e-01,
|
|
|
|
1.42857142725034663711e-01,
|
|
|
|
-1.11111104054623557880e-01,
|
|
|
|
9.09088713343650656196e-02,
|
|
|
|
-7.69187620504482999495e-02,
|
|
|
|
6.66107313738753120669e-02,
|
|
|
|
-5.83357013379057348645e-02,
|
|
|
|
4.97687799461593236017e-02,
|
|
|
|
-3.65315727442169155270e-02,
|
|
|
|
1.62858201153657823623e-02,
|
|
|
|
};
|
|
|
|
|
|
|
|
double w, s1, s2, z;
|
|
|
|
unsigned int ix, sign;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
#if _MSVCR_VER == 0
|
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "atan", x, 0, x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ix = *(ULONGLONG*)&x >> 32;
|
|
|
|
sign = ix >> 31;
|
|
|
|
ix &= 0x7fffffff;
|
|
|
|
if (ix >= 0x44100000) { /* if |x| >= 2^66 */
|
|
|
|
if (isnan(x))
|
|
|
|
return x;
|
|
|
|
z = atanhi[3] + 7.5231638452626401e-37;
|
|
|
|
return sign ? -z : z;
|
|
|
|
}
|
|
|
|
if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
|
|
|
|
if (ix < 0x3e400000) { /* |x| < 2^-27 */
|
|
|
|
if (ix < 0x00100000)
|
|
|
|
/* raise underflow for subnormal x */
|
|
|
|
fp_barrierf((float)x);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
id = -1;
|
|
|
|
} else {
|
|
|
|
x = fabs(x);
|
|
|
|
if (ix < 0x3ff30000) { /* |x| < 1.1875 */
|
|
|
|
if (ix < 0x3fe60000) { /* 7/16 <= |x| < 11/16 */
|
|
|
|
id = 0;
|
|
|
|
x = (2.0 * x - 1.0) / (2.0 + x);
|
|
|
|
} else { /* 11/16 <= |x| < 19/16 */
|
|
|
|
id = 1;
|
|
|
|
x = (x - 1.0) / (x + 1.0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ix < 0x40038000) { /* |x| < 2.4375 */
|
|
|
|
id = 2;
|
|
|
|
x = (x - 1.5) / (1.0 + 1.5 * x);
|
|
|
|
} else { /* 2.4375 <= |x| < 2^66 */
|
|
|
|
id = 3;
|
|
|
|
x = -1.0 / x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* end of argument reduction */
|
|
|
|
z = x * x;
|
|
|
|
w = z * z;
|
|
|
|
/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
|
|
|
|
s1 = z * (aT[0] + w * (aT[2] + w * (aT[4] + w * (aT[6] + w * (aT[8] + w * aT[10])))));
|
|
|
|
s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9]))));
|
|
|
|
if (id < 0)
|
|
|
|
return x - x * (s1 + s2);
|
|
|
|
z = atanhi[id] - (x * (s1 + s2) - atanlo[id] - x);
|
|
|
|
return sign ? -z : z;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_atan2 (MSVCRT.@)
|
2020-08-06 16:59:25 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/atan2.c
|
2006-01-14 17:36:23 +01:00
|
|
|
*/
|
2020-08-06 16:59:25 +02:00
|
|
|
double CDECL MSVCRT_atan2( double y, double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-08-06 16:59:25 +02:00
|
|
|
static const double pi = 3.1415926535897931160E+00,
|
|
|
|
pi_lo = 1.2246467991473531772E-16;
|
|
|
|
|
|
|
|
double z;
|
|
|
|
unsigned int m, lx, ly, ix, iy;
|
|
|
|
|
|
|
|
if (isnan(x) || isnan(y))
|
|
|
|
return x+y;
|
|
|
|
ix = *(ULONGLONG*)&x >> 32;
|
|
|
|
lx = *(ULONGLONG*)&x;
|
|
|
|
iy = *(ULONGLONG*)&y >> 32;
|
|
|
|
ly = *(ULONGLONG*)&y;
|
|
|
|
if (((ix - 0x3ff00000) | lx) == 0) /* x = 1.0 */
|
2020-11-18 16:01:52 +01:00
|
|
|
return MSVCRT_atan(y);
|
2020-08-06 16:59:25 +02:00
|
|
|
m = ((iy >> 31) & 1) | ((ix >> 30) & 2); /* 2*sign(x)+sign(y) */
|
|
|
|
ix = ix & 0x7fffffff;
|
|
|
|
iy = iy & 0x7fffffff;
|
|
|
|
|
|
|
|
/* when y = 0 */
|
|
|
|
if ((iy | ly) == 0) {
|
|
|
|
switch(m) {
|
|
|
|
case 0:
|
|
|
|
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
|
|
|
case 2: return pi; /* atan(+0,-anything) = pi */
|
|
|
|
case 3: return -pi; /* atan(-0,-anything) =-pi */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* when x = 0 */
|
|
|
|
if ((ix | lx) == 0)
|
|
|
|
return m & 1 ? -pi / 2 : pi / 2;
|
|
|
|
/* when x is INF */
|
|
|
|
if (ix == 0x7ff00000) {
|
|
|
|
if (iy == 0x7ff00000) {
|
|
|
|
switch(m) {
|
|
|
|
case 0: return pi / 4; /* atan(+INF,+INF) */
|
|
|
|
case 1: return -pi / 4; /* atan(-INF,+INF) */
|
|
|
|
case 2: return 3 * pi / 4; /* atan(+INF,-INF) */
|
|
|
|
case 3: return -3 * pi / 4; /* atan(-INF,-INF) */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(m) {
|
|
|
|
case 0: return 0.0; /* atan(+...,+INF) */
|
|
|
|
case 1: return -0.0; /* atan(-...,+INF) */
|
|
|
|
case 2: return pi; /* atan(+...,-INF) */
|
|
|
|
case 3: return -pi; /* atan(-...,-INF) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* |y/x| > 0x1p64 */
|
|
|
|
if (ix + (64 << 20) < iy || iy == 0x7ff00000)
|
|
|
|
return m & 1 ? -pi / 2 : pi / 2;
|
|
|
|
|
|
|
|
/* z = atan(|y/x|) without spurious underflow */
|
|
|
|
if ((m & 2) && iy + (64 << 20) < ix) /* |y/x| < 0x1p-64, x<0 */
|
|
|
|
z = 0;
|
|
|
|
else
|
2020-11-18 16:01:52 +01:00
|
|
|
z = MSVCRT_atan(fabs(y / x));
|
2020-08-06 16:59:25 +02:00
|
|
|
switch (m) {
|
|
|
|
case 0: return z; /* atan(+,+) */
|
|
|
|
case 1: return -z; /* atan(-,+) */
|
|
|
|
case 2: return pi - (z - pi_lo); /* atan(+,-) */
|
|
|
|
default: /* case 3 */
|
|
|
|
return (z - pi_lo) - pi; /* atan(-,-) */
|
|
|
|
}
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_cos (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_cos( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->cos( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "cos", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_cosh (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_cosh( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->cosh( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "cosh", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_exp (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_exp( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->exp( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "exp", x, 0, ret);
|
|
|
|
if (isfinite(x) && !ret) return math_error(_UNDERFLOW, "exp", x, 0, ret);
|
|
|
|
if (isfinite(x) && !isfinite(ret)) return math_error(_OVERFLOW, "exp", x, 0, ret);
|
2017-07-25 08:52:27 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_fmod (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_fmod( double x, double y )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->fmod( x, y );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (!isfinite(x) || !isfinite(y)) return math_error(_DOMAIN, "fmod", x, y, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_log (MSVCRT.@)
|
|
|
|
*/
|
2017-07-18 06:33:53 +02:00
|
|
|
double CDECL MSVCRT_log( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->log( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (x < 0.0) return math_error(_DOMAIN, "log", x, 0, ret);
|
|
|
|
if (x == 0.0) return math_error(_SING, "log", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_log10 (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_log10( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->log10( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (x < 0.0) return math_error(_DOMAIN, "log10", x, 0, ret);
|
|
|
|
if (x == 0.0) return math_error(_SING, "log10", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_pow (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_pow( double x, double y )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double z = unix_funcs->pow(x,y);
|
2020-11-18 16:01:52 +01:00
|
|
|
if (x < 0 && y != MSVCRT_floor(y))
|
2020-08-04 15:16:49 +02:00
|
|
|
return math_error(_DOMAIN, "pow", x, y, z);
|
|
|
|
if (!x && isfinite(y) && y < 0)
|
|
|
|
return math_error(_SING, "pow", x, y, z);
|
|
|
|
if (isfinite(x) && isfinite(y) && !isfinite(z))
|
|
|
|
return math_error(_OVERFLOW, "pow", x, y, z);
|
|
|
|
if (x && isfinite(x) && isfinite(y) && !z)
|
|
|
|
return math_error(_UNDERFLOW, "pow", x, y, z);
|
2006-01-14 17:36:23 +01:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sin (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_sin( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->sin( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "sin", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sinh (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_sinh( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->sinh( x );
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "sinh", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_sqrt (MSVCRT.@)
|
2020-08-04 15:17:33 +02:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/sqrt.c
|
2006-01-14 17:36:23 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_sqrt( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-08-04 15:17:33 +02:00
|
|
|
static const double tiny = 1.0e-300;
|
|
|
|
|
|
|
|
double z;
|
|
|
|
int sign = 0x80000000;
|
|
|
|
int ix0,s0,q,m,t,i;
|
|
|
|
unsigned int r,t1,s1,ix1,q1;
|
|
|
|
ULONGLONG ix;
|
|
|
|
|
|
|
|
ix = *(ULONGLONG*)&x;
|
|
|
|
ix0 = ix >> 32;
|
|
|
|
ix1 = ix;
|
|
|
|
|
|
|
|
/* take care of Inf and NaN */
|
|
|
|
if (isnan(x) || (isinf(x) && x > 0))
|
|
|
|
return x;
|
|
|
|
|
|
|
|
/* take care of zero */
|
|
|
|
if (ix0 <= 0) {
|
|
|
|
if (((ix0 & ~sign) | ix1) == 0)
|
|
|
|
return x; /* sqrt(+-0) = +-0 */
|
|
|
|
if (ix0 < 0)
|
|
|
|
return math_error(_DOMAIN, "sqrt", x, 0, (x - x) / (x - x));
|
|
|
|
}
|
|
|
|
/* normalize x */
|
|
|
|
m = ix0 >> 20;
|
|
|
|
if (m == 0) { /* subnormal x */
|
|
|
|
while (ix0 == 0) {
|
|
|
|
m -= 21;
|
|
|
|
ix0 |= (ix1 >> 11);
|
|
|
|
ix1 <<= 21;
|
|
|
|
}
|
|
|
|
for (i=0; (ix0 & 0x00100000) == 0; i++)
|
|
|
|
ix0 <<= 1;
|
|
|
|
m -= i - 1;
|
|
|
|
ix0 |= ix1 >> (32 - i);
|
|
|
|
ix1 <<= i;
|
|
|
|
}
|
|
|
|
m -= 1023; /* unbias exponent */
|
|
|
|
ix0 = (ix0 & 0x000fffff) | 0x00100000;
|
|
|
|
if (m & 1) { /* odd m, double x to make it even */
|
|
|
|
ix0 += ix0 + ((ix1 & sign) >> 31);
|
|
|
|
ix1 += ix1;
|
|
|
|
}
|
|
|
|
m >>= 1; /* m = [m/2] */
|
|
|
|
|
|
|
|
/* generate sqrt(x) bit by bit */
|
|
|
|
ix0 += ix0 + ((ix1 & sign) >> 31);
|
|
|
|
ix1 += ix1;
|
|
|
|
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
|
|
|
|
r = 0x00200000; /* r = moving bit from right to left */
|
|
|
|
|
|
|
|
while (r != 0) {
|
|
|
|
t = s0 + r;
|
|
|
|
if (t <= ix0) {
|
|
|
|
s0 = t + r;
|
|
|
|
ix0 -= t;
|
|
|
|
q += r;
|
|
|
|
}
|
|
|
|
ix0 += ix0 + ((ix1 & sign) >> 31);
|
|
|
|
ix1 += ix1;
|
|
|
|
r >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = sign;
|
|
|
|
while (r != 0) {
|
|
|
|
t1 = s1 + r;
|
|
|
|
t = s0;
|
|
|
|
if (t < ix0 || (t == ix0 && t1 <= ix1)) {
|
|
|
|
s1 = t1 + r;
|
|
|
|
if ((t1&sign) == sign && (s1 & sign) == 0)
|
|
|
|
s0++;
|
|
|
|
ix0 -= t;
|
|
|
|
if (ix1 < t1)
|
|
|
|
ix0--;
|
|
|
|
ix1 -= t1;
|
|
|
|
q1 += r;
|
|
|
|
}
|
|
|
|
ix0 += ix0 + ((ix1 & sign) >> 31);
|
|
|
|
ix1 += ix1;
|
|
|
|
r >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use floating add to find out rounding direction */
|
|
|
|
if ((ix0 | ix1) != 0) {
|
|
|
|
z = 1.0 - tiny; /* raise inexact flag */
|
|
|
|
if (z >= 1.0) {
|
|
|
|
z = 1.0 + tiny;
|
|
|
|
if (q1 == (unsigned int)0xffffffff) {
|
|
|
|
q1 = 0;
|
|
|
|
q++;
|
|
|
|
} else if (z > 1.0) {
|
|
|
|
if (q1 == (unsigned int)0xfffffffe)
|
|
|
|
q++;
|
|
|
|
q1 += 2;
|
|
|
|
} else
|
|
|
|
q1 += q1 & 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ix0 = (q >> 1) + 0x3fe00000;
|
|
|
|
ix1 = q1 >> 1;
|
|
|
|
if (q & 1)
|
|
|
|
ix1 |= sign;
|
|
|
|
ix = ix0 + ((unsigned int)m << 20);
|
|
|
|
ix <<= 32;
|
|
|
|
ix |= ix1;
|
|
|
|
return *(double*)&ix;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_tan (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_tan( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->tan(x);
|
2020-08-04 15:16:49 +02:00
|
|
|
if (!isfinite(x)) return math_error(_DOMAIN, "tan", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MSVCRT_tanh (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_tanh( double x )
|
2006-01-14 17:36:23 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->tanh(x);
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(x)) return math_error(_DOMAIN, "tanh", x, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2006-01-14 17:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
|
|
|
|
2017-11-27 20:29:44 +01:00
|
|
|
#define CREATE_FPU_FUNC1(name, call) \
|
|
|
|
__ASM_GLOBAL_FUNC(name, \
|
|
|
|
"pushl %ebp\n\t" \
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
|
|
|
|
"movl %esp, %ebp\n\t" \
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
|
|
|
|
"subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
|
|
|
|
"fstpl (%esp)\n\t" /* store function argument */ \
|
|
|
|
"fwait\n\t" \
|
|
|
|
"movl $1, %ecx\n\t" /* empty FPU stack */ \
|
|
|
|
"1:\n\t" \
|
|
|
|
"fxam\n\t" \
|
|
|
|
"fstsw %ax\n\t" \
|
|
|
|
"and $0x4500, %ax\n\t" \
|
|
|
|
"cmp $0x4100, %ax\n\t" \
|
|
|
|
"je 2f\n\t" \
|
|
|
|
"fstpl (%esp,%ecx,8)\n\t" \
|
|
|
|
"fwait\n\t" \
|
|
|
|
"incl %ecx\n\t" \
|
|
|
|
"jmp 1b\n\t" \
|
|
|
|
"2:\n\t" \
|
|
|
|
"movl %ecx, -4(%ebp)\n\t" \
|
|
|
|
"call " __ASM_NAME( #call ) "\n\t" \
|
|
|
|
"movl -4(%ebp), %ecx\n\t" \
|
|
|
|
"fstpl (%esp)\n\t" /* save result */ \
|
|
|
|
"3:\n\t" /* restore FPU stack */ \
|
|
|
|
"decl %ecx\n\t" \
|
|
|
|
"fldl (%esp,%ecx,8)\n\t" \
|
|
|
|
"cmpl $0, %ecx\n\t" \
|
|
|
|
"jne 3b\n\t" \
|
|
|
|
"leave\n\t" \
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t") \
|
|
|
|
"ret")
|
|
|
|
|
|
|
|
#define CREATE_FPU_FUNC2(name, call) \
|
|
|
|
__ASM_GLOBAL_FUNC(name, \
|
|
|
|
"pushl %ebp\n\t" \
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
|
|
|
|
"movl %esp, %ebp\n\t" \
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
|
|
|
|
"subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
|
|
|
|
"fstpl 8(%esp)\n\t" /* store function argument */ \
|
|
|
|
"fwait\n\t" \
|
|
|
|
"fstpl (%esp)\n\t" \
|
|
|
|
"fwait\n\t" \
|
|
|
|
"movl $2, %ecx\n\t" /* empty FPU stack */ \
|
|
|
|
"1:\n\t" \
|
|
|
|
"fxam\n\t" \
|
|
|
|
"fstsw %ax\n\t" \
|
|
|
|
"and $0x4500, %ax\n\t" \
|
|
|
|
"cmp $0x4100, %ax\n\t" \
|
|
|
|
"je 2f\n\t" \
|
|
|
|
"fstpl (%esp,%ecx,8)\n\t" \
|
|
|
|
"fwait\n\t" \
|
|
|
|
"incl %ecx\n\t" \
|
|
|
|
"jmp 1b\n\t" \
|
|
|
|
"2:\n\t" \
|
|
|
|
"movl %ecx, -4(%ebp)\n\t" \
|
|
|
|
"call " __ASM_NAME( #call ) "\n\t" \
|
|
|
|
"movl -4(%ebp), %ecx\n\t" \
|
|
|
|
"fstpl 8(%esp)\n\t" /* save result */ \
|
|
|
|
"3:\n\t" /* restore FPU stack */ \
|
|
|
|
"decl %ecx\n\t" \
|
|
|
|
"fldl (%esp,%ecx,8)\n\t" \
|
|
|
|
"cmpl $1, %ecx\n\t" \
|
|
|
|
"jne 3b\n\t" \
|
|
|
|
"leave\n\t" \
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t") \
|
|
|
|
"ret")
|
|
|
|
|
|
|
|
CREATE_FPU_FUNC1(_CIacos, MSVCRT_acos)
|
|
|
|
CREATE_FPU_FUNC1(_CIasin, MSVCRT_asin)
|
|
|
|
CREATE_FPU_FUNC1(_CIatan, MSVCRT_atan)
|
|
|
|
CREATE_FPU_FUNC2(_CIatan2, MSVCRT_atan2)
|
|
|
|
CREATE_FPU_FUNC1(_CIcos, MSVCRT_cos)
|
|
|
|
CREATE_FPU_FUNC1(_CIcosh, MSVCRT_cosh)
|
|
|
|
CREATE_FPU_FUNC1(_CIexp, MSVCRT_exp)
|
|
|
|
CREATE_FPU_FUNC2(_CIfmod, MSVCRT_fmod)
|
|
|
|
CREATE_FPU_FUNC1(_CIlog, MSVCRT_log)
|
|
|
|
CREATE_FPU_FUNC1(_CIlog10, MSVCRT_log10)
|
|
|
|
CREATE_FPU_FUNC2(_CIpow, MSVCRT_pow)
|
|
|
|
CREATE_FPU_FUNC1(_CIsin, MSVCRT_sin)
|
|
|
|
CREATE_FPU_FUNC1(_CIsinh, MSVCRT_sinh)
|
|
|
|
CREATE_FPU_FUNC1(_CIsqrt, MSVCRT_sqrt)
|
|
|
|
CREATE_FPU_FUNC1(_CItan, MSVCRT_tan)
|
|
|
|
CREATE_FPU_FUNC1(_CItanh, MSVCRT_tanh)
|
|
|
|
|
|
|
|
__ASM_GLOBAL_FUNC(MSVCRT__ftol,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp, %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"subl $12, %esp\n\t" /* sizeof(LONGLONG) + 2*sizeof(WORD) */
|
|
|
|
"fnstcw (%esp)\n\t"
|
|
|
|
"mov (%esp), %ax\n\t"
|
2017-12-18 12:10:28 +01:00
|
|
|
"or $0xc00, %ax\n\t"
|
2017-11-27 20:29:44 +01:00
|
|
|
"mov %ax, 2(%esp)\n\t"
|
|
|
|
"fldcw 2(%esp)\n\t"
|
|
|
|
"fistpq 4(%esp)\n\t"
|
|
|
|
"fldcw (%esp)\n\t"
|
|
|
|
"movl 4(%esp), %eax\n\t"
|
|
|
|
"movl 8(%esp), %edx\n\t"
|
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret")
|
2012-12-14 05:01:26 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#endif /* defined(__GNUC__) && defined(__i386__) */
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fpclass (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__fpclass(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-16 12:10:53 +01:00
|
|
|
union { double f; UINT64 i; } u = { num };
|
|
|
|
int e = u.i >> 52 & 0x7ff;
|
|
|
|
int s = u.i >> 63;
|
|
|
|
|
|
|
|
switch (e)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (u.i << 1) return s ? MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
|
|
|
|
return s ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
|
|
|
|
case 0x7ff:
|
|
|
|
if (u.i << 12) return ((u.i >> 51) & 1) ? MSVCRT__FPCLASS_QNAN : MSVCRT__FPCLASS_SNAN;
|
|
|
|
return s ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
|
|
|
|
default:
|
|
|
|
return s ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _rotl (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _rotl(unsigned int num, int shift)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
shift &= 31;
|
|
|
|
return (num << shift) | (num >> (32-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _lrotl (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_ulong CDECL MSVCRT__lrotl(__msvcrt_ulong num, int shift)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
shift &= 0x1f;
|
|
|
|
return (num << shift) | (num >> (32-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _lrotr (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_ulong CDECL MSVCRT__lrotr(__msvcrt_ulong num, int shift)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
shift &= 0x1f;
|
|
|
|
return (num >> shift) | (num << (32-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _rotr (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _rotr(unsigned int num, int shift)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
shift &= 0x1f;
|
|
|
|
return (num >> shift) | (num << (32-shift));
|
|
|
|
}
|
|
|
|
|
2011-05-01 12:52:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _rotl64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
|
|
|
|
{
|
|
|
|
shift &= 63;
|
|
|
|
return (num << shift) | (num >> (64-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _rotr64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
|
|
|
|
{
|
|
|
|
shift &= 63;
|
|
|
|
return (num >> shift) | (num << (64-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* abs (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_abs( int n )
|
|
|
|
{
|
|
|
|
return n >= 0 ? n : -n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* labs (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCRT_labs( __msvcrt_long n )
|
2011-05-01 12:52:22 +02:00
|
|
|
{
|
|
|
|
return n >= 0 ? n : -n;
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=100
|
2014-08-29 18:31:18 +02:00
|
|
|
/*********************************************************************
|
2017-12-22 18:38:56 +01:00
|
|
|
* llabs (MSVCR100.@)
|
2014-08-29 18:31:18 +02:00
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCRT_llabs( __int64 n )
|
2014-08-29 18:31:18 +02:00
|
|
|
{
|
|
|
|
return n >= 0 ? n : -n;
|
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif
|
2014-08-29 18:31:18 +02:00
|
|
|
|
2020-09-11 17:38:59 +02:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
/*********************************************************************
|
|
|
|
* imaxabs (MSVCR120.@)
|
|
|
|
*/
|
2020-11-20 12:35:52 +01:00
|
|
|
intmax_t CDECL MSVCRT_imaxabs( intmax_t n )
|
2020-09-11 17:38:59 +02:00
|
|
|
{
|
|
|
|
return n >= 0 ? n : -n;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-01 12:52:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _abs64 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
__int64 CDECL _abs64( __int64 n )
|
|
|
|
{
|
|
|
|
return n >= 0 ? n : -n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _logb (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__logb(double num)
|
2011-05-01 12:52:22 +02:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->logb(num);
|
2020-08-04 15:16:49 +02:00
|
|
|
if (isnan(num)) return math_error(_DOMAIN, "_logb", num, 0, ret);
|
|
|
|
if (!num) return math_error(_SING, "_logb", num, 0, ret);
|
2017-08-02 07:51:36 +02:00
|
|
|
return ret;
|
2011-05-01 12:52:22 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _hypot (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL _hypot(double x, double y)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: errno handling */
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->hypot( x, y );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2010-05-01 16:32:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _hypotf (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
float CDECL MSVCRT__hypotf(float x, float y)
|
2010-05-01 16:32:19 +02:00
|
|
|
{
|
|
|
|
/* FIXME: errno handling */
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->hypotf( x, y );
|
2010-05-01 16:32:19 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ceil (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_ceil( double x )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->ceil(x);
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* floor (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_floor( double x )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->floor(x);
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-21 23:50:42 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fma (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_fma( double x, double y, double z )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double w = unix_funcs->fma(x, y, z);
|
2020-11-30 14:37:27 +01:00
|
|
|
if ((isinf(x) && y == 0) || (x == 0 && isinf(y))) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (isinf(x) && isinf(z) && x != z) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (isinf(y) && isinf(z) && y != z) *MSVCRT__errno() = EDOM;
|
2019-05-21 23:50:42 +02:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2019-07-30 23:08:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fmaf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_fmaf( float x, float y, float z )
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float w = unix_funcs->fmaf(x, y, z);
|
2020-11-30 14:37:27 +01:00
|
|
|
if ((isinf(x) && y == 0) || (x == 0 && isinf(y))) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (isinf(x) && isinf(z) && x != z) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (isinf(y) && isinf(z) && y != z) *MSVCRT__errno() = EDOM;
|
2019-07-30 23:08:49 +02:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* fabs (MSVCRT.@)
|
2020-11-17 09:58:19 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/fabsf.c
|
2006-01-14 17:40:29 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_fabs( double x )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2020-11-17 09:58:19 +01:00
|
|
|
union { double f; UINT64 i; } u = { x };
|
|
|
|
u.i &= ~0ull >> 1;
|
|
|
|
return u.f;
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* frexp (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_frexp( double x, int *exp )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->frexp( x, exp );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* modf (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
double CDECL MSVCRT_modf( double x, double *iptr )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->modf( x, iptr );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:39:29 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* _statusfp2 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Not exported by native msvcrt, added in msvcr80.
|
|
|
|
*/
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned long fpword;
|
|
|
|
|
|
|
|
if (x86_sw)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
|
|
|
|
flags = 0;
|
|
|
|
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
|
|
|
|
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
*x86_sw = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sse2_sw) return;
|
|
|
|
|
|
|
|
if (sse2_supported)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
|
|
|
|
flags = 0;
|
|
|
|
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
|
|
|
|
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
*sse2_sw = flags;
|
|
|
|
}
|
|
|
|
else *sse2_sw = 0;
|
|
|
|
#else
|
|
|
|
FIXME( "not implemented\n" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* _statusfp (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _statusfp(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2019-10-31 22:20:14 +01:00
|
|
|
unsigned int flags = 0;
|
2011-01-25 21:39:29 +01:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
unsigned int x86_sw, sse2_sw;
|
|
|
|
|
|
|
|
_statusfp2( &x86_sw, &sse2_sw );
|
|
|
|
/* FIXME: there's no definition for ambiguous status, just return all status bits for now */
|
2019-10-31 22:20:14 +01:00
|
|
|
flags = x86_sw | sse2_sw;
|
|
|
|
#elif defined(__aarch64__)
|
2020-11-26 17:11:47 +01:00
|
|
|
ULONG_PTR fpsr;
|
2019-10-31 22:20:14 +01:00
|
|
|
|
|
|
|
__asm__ __volatile__( "mrs %0, fpsr" : "=r" (fpsr) );
|
|
|
|
if (fpsr & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpsr & 0x2) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpsr & 0x4) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpsr & 0x8) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpsr & 0x10) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
if (fpsr & 0x80) flags |= MSVCRT__SW_DENORMAL;
|
2001-01-11 00:59:25 +01:00
|
|
|
#else
|
2011-01-25 21:39:29 +01:00
|
|
|
FIXME( "not implemented\n" );
|
2001-01-11 00:59:25 +01:00
|
|
|
#endif
|
2019-10-31 22:20:14 +01:00
|
|
|
return flags;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _clearfp (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _clearfp(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-01-25 21:59:45 +01:00
|
|
|
unsigned int flags = 0;
|
|
|
|
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
|
|
|
unsigned long fpword;
|
|
|
|
|
|
|
|
__asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
|
|
|
|
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
|
|
|
|
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
|
|
|
|
if (sse2_supported)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
|
|
|
|
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
|
|
|
|
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
fpword &= ~0x3f;
|
|
|
|
__asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
|
|
|
|
}
|
2019-10-31 22:20:14 +01:00
|
|
|
#elif defined(__aarch64__)
|
2020-11-26 17:11:47 +01:00
|
|
|
ULONG_PTR fpsr;
|
2019-10-31 22:20:14 +01:00
|
|
|
|
|
|
|
__asm__ __volatile__( "mrs %0, fpsr" : "=r" (fpsr) );
|
|
|
|
if (fpsr & 0x1) flags |= MSVCRT__SW_INVALID;
|
|
|
|
if (fpsr & 0x2) flags |= MSVCRT__SW_ZERODIVIDE;
|
|
|
|
if (fpsr & 0x4) flags |= MSVCRT__SW_OVERFLOW;
|
|
|
|
if (fpsr & 0x8) flags |= MSVCRT__SW_UNDERFLOW;
|
|
|
|
if (fpsr & 0x10) flags |= MSVCRT__SW_INEXACT;
|
|
|
|
if (fpsr & 0x80) flags |= MSVCRT__SW_DENORMAL;
|
|
|
|
fpsr &= ~0x9f;
|
|
|
|
__asm__ __volatile__( "msr fpsr, %0" :: "r" (fpsr) );
|
2001-01-11 00:59:25 +01:00
|
|
|
#else
|
2011-01-25 21:59:45 +01:00
|
|
|
FIXME( "not implemented\n" );
|
2001-01-11 00:59:25 +01:00
|
|
|
#endif
|
2011-01-25 21:59:45 +01:00
|
|
|
return flags;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2004-01-13 06:45:05 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __fpecode (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int * CDECL __fpecode(void)
|
2004-01-13 06:45:05 +01:00
|
|
|
{
|
|
|
|
return &msvcrt_get_thread_data()->fpecode;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ldexp (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
double CDECL MSVCRT_ldexp(double num, __msvcrt_long exp)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double z = unix_funcs->ldexp(num,exp);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2017-07-25 08:52:27 +02:00
|
|
|
if (isfinite(num) && !isfinite(z))
|
2020-08-04 15:16:49 +02:00
|
|
|
return math_error(_OVERFLOW, "ldexp", num, exp, z);
|
|
|
|
if (num && isfinite(num) && !z)
|
|
|
|
return math_error(_UNDERFLOW, "ldexp", num, exp, z);
|
|
|
|
if (z == 0 && signbit(z))
|
2001-01-11 00:59:25 +01:00
|
|
|
z = 0.0; /* Convert -0 -> +0 */
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _cabs (MSVCRT.@)
|
|
|
|
*/
|
2020-11-20 12:35:52 +01:00
|
|
|
double CDECL MSVCRT__cabs(struct _complex num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-18 16:01:52 +01:00
|
|
|
return MSVCRT_sqrt(num.x * num.x + num.y * num.y);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _chgsign (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__chgsign(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-16 15:04:00 +01:00
|
|
|
union { double f; UINT64 i; } u = { num };
|
|
|
|
u.i ^= 1ull << 63;
|
|
|
|
return u.f;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:01:12 +01:00
|
|
|
/*********************************************************************
|
2018-01-10 07:21:46 +01:00
|
|
|
* __control87_2 (MSVCR80.@)
|
2011-01-25 21:01:12 +01:00
|
|
|
*
|
|
|
|
* Not exported by native msvcrt, added in msvcr80.
|
|
|
|
*/
|
2019-11-02 14:35:52 +01:00
|
|
|
#ifdef __i386__
|
2011-01-25 21:01:12 +01:00
|
|
|
int CDECL __control87_2( unsigned int newval, unsigned int mask,
|
|
|
|
unsigned int *x86_cw, unsigned int *sse2_cw )
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
unsigned long fpword;
|
|
|
|
unsigned int flags;
|
2020-07-07 16:07:39 +02:00
|
|
|
unsigned int old_flags;
|
2011-01-25 21:01:12 +01:00
|
|
|
|
|
|
|
if (x86_cw)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
|
|
|
|
|
|
|
|
/* Convert into mask constants */
|
|
|
|
flags = 0;
|
|
|
|
if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
|
|
|
|
if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
|
|
|
|
if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
|
|
|
|
if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
|
|
|
|
if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
|
|
|
|
if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
|
|
|
|
switch (fpword & 0xc00)
|
|
|
|
{
|
|
|
|
case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
|
|
|
|
case 0x800: flags |= MSVCRT__RC_UP; break;
|
|
|
|
case 0x400: flags |= MSVCRT__RC_DOWN; break;
|
|
|
|
}
|
|
|
|
switch (fpword & 0x300)
|
|
|
|
{
|
|
|
|
case 0x0: flags |= MSVCRT__PC_24; break;
|
|
|
|
case 0x200: flags |= MSVCRT__PC_53; break;
|
|
|
|
case 0x300: flags |= MSVCRT__PC_64; break;
|
|
|
|
}
|
|
|
|
if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
|
|
|
|
|
|
|
|
TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
flags = (flags & ~mask) | (newval & mask);
|
|
|
|
|
|
|
|
/* Convert (masked) value back to fp word */
|
|
|
|
fpword = 0;
|
|
|
|
if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
|
|
|
|
if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
|
|
|
|
if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
|
|
|
|
if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
|
|
|
|
if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
|
|
|
|
if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
|
|
|
|
switch (flags & MSVCRT__MCW_RC)
|
|
|
|
{
|
|
|
|
case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
|
|
|
|
case MSVCRT__RC_UP: fpword |= 0x800; break;
|
|
|
|
case MSVCRT__RC_DOWN: fpword |= 0x400; break;
|
|
|
|
}
|
|
|
|
switch (flags & MSVCRT__MCW_PC)
|
|
|
|
{
|
|
|
|
case MSVCRT__PC_64: fpword |= 0x300; break;
|
|
|
|
case MSVCRT__PC_53: fpword |= 0x200; break;
|
|
|
|
case MSVCRT__PC_24: fpword |= 0x0; break;
|
|
|
|
}
|
|
|
|
if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
|
|
|
|
|
|
|
|
__asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
|
|
|
|
}
|
|
|
|
*x86_cw = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sse2_cw) return 1;
|
|
|
|
|
|
|
|
if (sse2_supported)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
|
|
|
|
|
|
|
|
/* Convert into mask constants */
|
|
|
|
flags = 0;
|
|
|
|
if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
|
|
|
|
if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
|
|
|
|
if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
|
|
|
|
if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
|
|
|
|
if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
|
|
|
|
if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
|
|
|
|
switch (fpword & 0x6000)
|
|
|
|
{
|
|
|
|
case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
|
|
|
|
case 0x4000: flags |= MSVCRT__RC_UP; break;
|
|
|
|
case 0x2000: flags |= MSVCRT__RC_DOWN; break;
|
|
|
|
}
|
|
|
|
switch (fpword & 0x8040)
|
|
|
|
{
|
|
|
|
case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
|
|
|
|
case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
|
|
|
|
case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
|
|
|
|
if (mask)
|
|
|
|
{
|
2020-07-07 16:07:39 +02:00
|
|
|
old_flags = flags;
|
|
|
|
mask &= MSVCRT__MCW_EM | MSVCRT__MCW_RC | MSVCRT__MCW_DN;
|
2011-01-25 21:01:12 +01:00
|
|
|
flags = (flags & ~mask) | (newval & mask);
|
|
|
|
|
2020-07-07 16:07:39 +02:00
|
|
|
if (flags != old_flags)
|
2011-01-25 21:01:12 +01:00
|
|
|
{
|
2020-07-07 16:07:39 +02:00
|
|
|
/* Convert (masked) value back to fp word */
|
|
|
|
fpword = 0;
|
|
|
|
if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
|
|
|
|
if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
|
|
|
|
if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
|
|
|
|
if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
|
|
|
|
if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
|
|
|
|
if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
|
|
|
|
switch (flags & MSVCRT__MCW_RC)
|
|
|
|
{
|
|
|
|
case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
|
|
|
|
case MSVCRT__RC_UP: fpword |= 0x4000; break;
|
|
|
|
case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
|
|
|
|
}
|
|
|
|
switch (flags & MSVCRT__MCW_DN)
|
|
|
|
{
|
|
|
|
case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
|
|
|
|
case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
|
|
|
|
case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
|
|
|
|
}
|
|
|
|
__asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
|
2011-01-25 21:01:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*sse2_cw = flags;
|
|
|
|
}
|
|
|
|
else *sse2_cw = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
FIXME( "not implemented\n" );
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _control87 (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2019-10-31 22:20:14 +01:00
|
|
|
unsigned int flags = 0;
|
2019-11-02 14:35:52 +01:00
|
|
|
#ifdef __i386__
|
2019-10-31 22:20:14 +01:00
|
|
|
unsigned int sse2_cw;
|
|
|
|
|
|
|
|
__control87_2( newval, mask, &flags, &sse2_cw );
|
|
|
|
|
|
|
|
if ((flags ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) flags |= MSVCRT__EM_AMBIGUOUS;
|
2020-07-07 16:08:00 +02:00
|
|
|
flags |= sse2_cw;
|
2019-11-02 14:35:52 +01:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
unsigned long fpword;
|
2020-07-07 16:07:39 +02:00
|
|
|
unsigned int old_flags;
|
2019-11-02 14:35:52 +01:00
|
|
|
|
|
|
|
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
|
|
|
|
if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
|
|
|
|
if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
|
|
|
|
if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
|
|
|
|
if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
|
|
|
|
if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
|
|
|
|
if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
|
|
|
|
switch (fpword & 0x6000)
|
|
|
|
{
|
|
|
|
case 0x6000: flags |= MSVCRT__RC_CHOP; break;
|
|
|
|
case 0x4000: flags |= MSVCRT__RC_UP; break;
|
|
|
|
case 0x2000: flags |= MSVCRT__RC_DOWN; break;
|
|
|
|
}
|
|
|
|
switch (fpword & 0x8040)
|
|
|
|
{
|
|
|
|
case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
|
|
|
|
case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
|
|
|
|
case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
|
|
|
|
}
|
2020-07-07 16:07:39 +02:00
|
|
|
old_flags = flags;
|
|
|
|
mask &= MSVCRT__MCW_EM | MSVCRT__MCW_RC | MSVCRT__MCW_DN;
|
2019-11-02 14:35:52 +01:00
|
|
|
flags = (flags & ~mask) | (newval & mask);
|
2020-07-07 16:07:39 +02:00
|
|
|
if (flags != old_flags)
|
2019-11-02 14:35:52 +01:00
|
|
|
{
|
2020-07-07 16:07:39 +02:00
|
|
|
fpword = 0;
|
|
|
|
if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
|
|
|
|
if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
|
|
|
|
if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
|
|
|
|
if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
|
|
|
|
if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
|
|
|
|
if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
|
|
|
|
switch (flags & MSVCRT__MCW_RC)
|
|
|
|
{
|
|
|
|
case MSVCRT__RC_CHOP: fpword |= 0x6000; break;
|
|
|
|
case MSVCRT__RC_UP: fpword |= 0x4000; break;
|
|
|
|
case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
|
|
|
|
}
|
|
|
|
switch (flags & MSVCRT__MCW_DN)
|
|
|
|
{
|
|
|
|
case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
|
|
|
|
case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
|
|
|
|
case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
|
|
|
|
}
|
|
|
|
__asm__ __volatile__( "ldmxcsr %0" :: "m" (fpword) );
|
2019-11-02 14:35:52 +01:00
|
|
|
}
|
2019-10-31 22:20:14 +01:00
|
|
|
#elif defined(__aarch64__)
|
2020-11-26 17:11:47 +01:00
|
|
|
ULONG_PTR fpcr;
|
2019-10-31 22:20:14 +01:00
|
|
|
|
|
|
|
__asm__ __volatile__( "mrs %0, fpcr" : "=r" (fpcr) );
|
|
|
|
if (!(fpcr & 0x100)) flags |= MSVCRT__EM_INVALID;
|
|
|
|
if (!(fpcr & 0x200)) flags |= MSVCRT__EM_ZERODIVIDE;
|
|
|
|
if (!(fpcr & 0x400)) flags |= MSVCRT__EM_OVERFLOW;
|
|
|
|
if (!(fpcr & 0x800)) flags |= MSVCRT__EM_UNDERFLOW;
|
|
|
|
if (!(fpcr & 0x1000)) flags |= MSVCRT__EM_INEXACT;
|
|
|
|
if (!(fpcr & 0x8000)) flags |= MSVCRT__EM_DENORMAL;
|
|
|
|
switch (fpcr & 0xc00000)
|
|
|
|
{
|
|
|
|
case 0x400000: flags |= MSVCRT__RC_UP; break;
|
|
|
|
case 0x800000: flags |= MSVCRT__RC_DOWN; break;
|
|
|
|
case 0xc00000: flags |= MSVCRT__RC_CHOP; break;
|
|
|
|
}
|
|
|
|
flags = (flags & ~mask) | (newval & mask);
|
|
|
|
fpcr &= ~0xc09f00ul;
|
|
|
|
if (!(flags & MSVCRT__EM_INVALID)) fpcr |= 0x100;
|
|
|
|
if (!(flags & MSVCRT__EM_ZERODIVIDE)) fpcr |= 0x200;
|
|
|
|
if (!(flags & MSVCRT__EM_OVERFLOW)) fpcr |= 0x400;
|
|
|
|
if (!(flags & MSVCRT__EM_UNDERFLOW)) fpcr |= 0x800;
|
|
|
|
if (!(flags & MSVCRT__EM_INEXACT)) fpcr |= 0x1000;
|
|
|
|
if (!(flags & MSVCRT__EM_DENORMAL)) fpcr |= 0x8000;
|
|
|
|
switch (flags & MSVCRT__MCW_RC)
|
|
|
|
{
|
|
|
|
case MSVCRT__RC_CHOP: fpcr |= 0xc00000; break;
|
|
|
|
case MSVCRT__RC_UP: fpcr |= 0x400000; break;
|
|
|
|
case MSVCRT__RC_DOWN: fpcr |= 0x800000; break;
|
|
|
|
}
|
|
|
|
__asm__ __volatile__( "msr fpcr, %0" :: "r" (fpcr) );
|
2001-01-11 00:59:25 +01:00
|
|
|
#else
|
2011-01-25 21:01:12 +01:00
|
|
|
FIXME( "not implemented\n" );
|
2001-01-11 00:59:25 +01:00
|
|
|
#endif
|
2019-10-31 22:20:14 +01:00
|
|
|
return flags;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _controlfp (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-06-25 03:19:15 +02:00
|
|
|
return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 22:27:17 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_controlfp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
|
|
|
|
{
|
|
|
|
_controlfp( newval, mask );
|
|
|
|
}
|
|
|
|
|
2010-04-01 12:41:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _controlfp_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
|
|
|
|
{
|
2010-11-26 14:57:24 +01:00
|
|
|
static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
|
|
|
|
MSVCRT__MCW_PC | MSVCRT__MCW_DN);
|
2010-11-27 20:40:14 +01:00
|
|
|
unsigned int val;
|
2010-04-01 12:41:06 +02:00
|
|
|
|
2010-11-27 20:40:14 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
|
2010-11-26 14:57:24 +01:00
|
|
|
{
|
2010-11-27 20:40:14 +01:00
|
|
|
if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
|
2020-11-30 14:37:27 +01:00
|
|
|
return EINVAL;
|
2010-11-26 14:57:24 +01:00
|
|
|
}
|
2010-11-27 20:40:14 +01:00
|
|
|
val = _controlfp( newval, mask );
|
|
|
|
if (cur) *cur = val;
|
2010-04-01 12:41:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=120
|
2016-07-04 11:04:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fegetenv (MSVCR120.@)
|
|
|
|
*/
|
2020-11-20 12:51:23 +01:00
|
|
|
int CDECL MSVCRT_fegetenv(fenv_t *env)
|
2016-07-04 11:04:23 +02:00
|
|
|
{
|
2020-11-20 12:51:23 +01:00
|
|
|
env->_Fe_ctl = _controlfp(0, 0) & (MSVCRT__EM_INEXACT | MSVCRT__EM_UNDERFLOW |
|
2020-11-17 21:07:49 +01:00
|
|
|
MSVCRT__EM_OVERFLOW | MSVCRT__EM_ZERODIVIDE | MSVCRT__EM_INVALID | MSVCRT__RC_CHOP);
|
2020-11-20 12:51:23 +01:00
|
|
|
env->_Fe_stat = _statusfp();
|
2016-07-04 11:04:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif
|
2016-07-04 11:04:23 +02:00
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=140
|
2016-06-13 11:34:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __fpe_flt_rounds (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL __fpe_flt_rounds(void)
|
|
|
|
{
|
|
|
|
unsigned int fpc = _controlfp(0, 0) & MSVCRT__RC_CHOP;
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
switch(fpc) {
|
|
|
|
case MSVCRT__RC_CHOP: return 0;
|
|
|
|
case MSVCRT__RC_NEAR: return 1;
|
|
|
|
case MSVCRT__RC_UP: return 2;
|
|
|
|
default: return 3;
|
|
|
|
}
|
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _MSVCR_VER>=120
|
2016-06-13 11:34:49 +02:00
|
|
|
|
2017-03-31 16:05:35 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fegetround (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_fegetround(void)
|
|
|
|
{
|
|
|
|
return _controlfp(0, 0) & MSVCRT__RC_CHOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* fesetround (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_fesetround(int round_mode)
|
|
|
|
{
|
|
|
|
if (round_mode & (~MSVCRT__RC_CHOP))
|
|
|
|
return 1;
|
|
|
|
_controlfp(round_mode, MSVCRT__RC_CHOP);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif /* _MSVCR_VER>=120 */
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _copysign (MSVCRT.@)
|
2020-11-17 09:57:52 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/copysign.c
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2020-11-17 09:57:52 +01:00
|
|
|
double CDECL MSVCRT__copysign( double x, double y )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-17 09:57:52 +01:00
|
|
|
union { double f; UINT64 i; } ux = { x }, uy = { y };
|
|
|
|
ux.i &= ~0ull >> 1;
|
|
|
|
ux.i |= uy.i & 1ull << 63;
|
|
|
|
return ux.f;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _finite (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
int CDECL MSVCRT__finite(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-16 12:17:52 +01:00
|
|
|
union { double f; UINT64 i; } u = { num };
|
|
|
|
return (u.i & ~0ull >> 1) < 0x7ffull << 52;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fpreset (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _fpreset(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-01-25 22:12:16 +01:00
|
|
|
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
|
|
|
const unsigned int x86_cw = 0x27f;
|
|
|
|
__asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
|
|
|
|
if (sse2_supported)
|
|
|
|
{
|
|
|
|
const unsigned long sse2_cw = 0x1f80;
|
|
|
|
__asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
#else
|
2011-01-25 22:12:16 +01:00
|
|
|
FIXME( "not implemented\n" );
|
2001-01-11 00:59:25 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=120
|
2017-02-07 17:42:34 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* fesetenv (MSVCR120.@)
|
|
|
|
*/
|
2020-11-20 12:51:23 +01:00
|
|
|
int CDECL MSVCRT_fesetenv(const fenv_t *env)
|
2017-02-07 17:42:34 +01:00
|
|
|
{
|
2017-02-07 17:42:43 +01:00
|
|
|
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
|
|
|
struct {
|
|
|
|
WORD control_word;
|
|
|
|
WORD unused1;
|
|
|
|
WORD status_word;
|
|
|
|
WORD unused2;
|
|
|
|
WORD tag_word;
|
|
|
|
WORD unused3;
|
|
|
|
DWORD instruction_pointer;
|
|
|
|
WORD code_segment;
|
|
|
|
WORD unused4;
|
|
|
|
DWORD operand_addr;
|
|
|
|
WORD data_segment;
|
|
|
|
WORD unused5;
|
|
|
|
} fenv;
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", env );
|
|
|
|
|
2020-11-20 12:51:23 +01:00
|
|
|
if (!env->_Fe_ctl && !env->_Fe_stat) {
|
2017-02-07 17:42:43 +01:00
|
|
|
_fpreset();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__asm__ __volatile__( "fnstenv %0" : "=m" (fenv) );
|
|
|
|
|
2020-11-17 21:07:49 +01:00
|
|
|
fenv.control_word &= ~0xc3d;
|
2020-11-20 12:51:23 +01:00
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_INVALID) fenv.control_word |= 0x1;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_ZERODIVIDE) fenv.control_word |= 0x4;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_OVERFLOW) fenv.control_word |= 0x8;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_UNDERFLOW) fenv.control_word |= 0x10;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_INEXACT) fenv.control_word |= 0x20;
|
|
|
|
switch (env->_Fe_ctl & MSVCRT__MCW_RC)
|
2020-11-17 21:07:49 +01:00
|
|
|
{
|
|
|
|
case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fenv.control_word |= 0xc00; break;
|
|
|
|
case MSVCRT__RC_UP: fenv.control_word |= 0x800; break;
|
|
|
|
case MSVCRT__RC_DOWN: fenv.control_word |= 0x400; break;
|
|
|
|
}
|
2017-02-07 17:42:43 +01:00
|
|
|
|
|
|
|
fenv.status_word &= ~0x3d;
|
2020-11-20 12:51:23 +01:00
|
|
|
if (env->_Fe_stat & FE_INVALID) fenv.status_word |= 0x1;
|
|
|
|
if (env->_Fe_stat & FE_DIVBYZERO) fenv.status_word |= 0x4;
|
|
|
|
if (env->_Fe_stat & FE_OVERFLOW) fenv.status_word |= 0x8;
|
|
|
|
if (env->_Fe_stat & FE_UNDERFLOW) fenv.status_word |= 0x10;
|
|
|
|
if (env->_Fe_stat & FE_INEXACT) fenv.status_word |= 0x20;
|
2017-02-07 17:42:43 +01:00
|
|
|
|
|
|
|
__asm__ __volatile__( "fldenv %0" : : "m" (fenv) : "st", "st(1)",
|
|
|
|
"st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
|
|
|
|
|
|
|
|
if (sse2_supported)
|
|
|
|
{
|
|
|
|
DWORD fpword;
|
|
|
|
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
|
2020-11-17 21:07:49 +01:00
|
|
|
fpword &= ~0x7e80;
|
2020-11-20 12:51:23 +01:00
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_INVALID) fpword |= 0x80;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
|
|
|
|
if (env->_Fe_ctl & MSVCRT__EM_INEXACT) fpword |= 0x1000;
|
|
|
|
switch (env->_Fe_ctl & MSVCRT__MCW_RC)
|
2020-11-17 21:07:49 +01:00
|
|
|
{
|
|
|
|
case MSVCRT__RC_CHOP: fpword |= 0x6000; break;
|
|
|
|
case MSVCRT__RC_UP: fpword |= 0x4000; break;
|
|
|
|
case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
|
|
|
|
}
|
2017-02-07 17:42:43 +01:00
|
|
|
__asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
|
|
|
|
}
|
|
|
|
|
2017-02-07 17:42:34 +01:00
|
|
|
return 0;
|
2017-02-07 17:42:43 +01:00
|
|
|
#else
|
|
|
|
FIXME( "not implemented\n" );
|
|
|
|
#endif
|
|
|
|
return 1;
|
2017-02-07 17:42:34 +01:00
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif
|
2017-02-07 17:42:34 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _isnan (MSVCRT.@)
|
|
|
|
*/
|
2020-11-16 12:18:03 +01:00
|
|
|
int CDECL MSVCRT__isnan(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-16 12:18:03 +01:00
|
|
|
union { double f; UINT64 i; } u = { num };
|
|
|
|
return (u.i & ~0ull >> 1) > 0x7ffull << 52;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _j0 (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__j0(double num)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: errno handling */
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->j0( num );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _j1 (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__j1(double num)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: errno handling */
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->j1( num );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2011-06-03 15:28:32 +02:00
|
|
|
* _jn (MSVCRT.@)
|
2006-01-14 17:40:29 +01:00
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__jn(int n, double num)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
/* FIXME: errno handling */
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->jn( n, num );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _y0 (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__y0(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
double retval;
|
2020-11-18 16:14:50 +01:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(num)) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
retval = unix_funcs->y0( num );
|
2011-06-03 15:28:32 +02:00
|
|
|
if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2018-03-02 18:02:46 +01:00
|
|
|
retval = NAN;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _y1 (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__y1(double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
double retval;
|
2020-11-18 16:14:50 +01:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(num)) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
retval = unix_funcs->y1( num );
|
2011-06-03 15:28:32 +02:00
|
|
|
if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2018-03-02 18:02:46 +01:00
|
|
|
retval = NAN;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _yn (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__yn(int order, double num)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
double retval;
|
2020-11-18 16:14:50 +01:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(num)) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
retval = unix_funcs->yn( order, num );
|
2011-06-03 15:28:32 +02:00
|
|
|
if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2018-03-02 18:02:46 +01:00
|
|
|
retval = NAN;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
|
2016-11-22 09:39:50 +01:00
|
|
|
/*********************************************************************
|
2017-12-22 18:38:56 +01:00
|
|
|
* _nearbyint (MSVCR120.@)
|
2016-11-22 09:39:50 +01:00
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_nearbyint(double num)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->nearbyint( num );
|
2016-11-22 09:39:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2017-12-22 18:38:56 +01:00
|
|
|
* _nearbyintf (MSVCR120.@)
|
2016-11-22 09:39:50 +01:00
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_nearbyintf(float num)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->nearbyintf( num );
|
2016-11-22 09:39:50 +01:00
|
|
|
}
|
|
|
|
|
2019-02-23 21:46:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* nexttoward (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCRT_nexttoward(double num, double next)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->nexttoward(num, next);
|
2019-02-23 21:46:46 +01:00
|
|
|
if (!(MSVCRT__fpclass(ret) & (MSVCRT__FPCLASS_PN | MSVCRT__FPCLASS_NN
|
|
|
|
| MSVCRT__FPCLASS_SNAN | MSVCRT__FPCLASS_QNAN)) && !isinf(num))
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
2019-02-23 21:46:46 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* nexttowardf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCRT_nexttowardf(float num, double next)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->nexttowardf( num, next );
|
2019-02-23 21:46:46 +01:00
|
|
|
if (!(MSVCRT__fpclass(ret) & (MSVCRT__FPCLASS_PN | MSVCRT__FPCLASS_NN
|
|
|
|
| MSVCRT__FPCLASS_SNAN | MSVCRT__FPCLASS_QNAN)) && !isinf(num))
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
2019-02-23 21:46:46 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif /* _MSVCR_VER>=120 */
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _nextafter (MSVCRT.@)
|
|
|
|
*/
|
2011-06-03 15:28:32 +02:00
|
|
|
double CDECL MSVCRT__nextafter(double num, double next)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
double retval;
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
retval = unix_funcs->nextafter(num,next);
|
2001-01-11 00:59:25 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-03-21 00:47:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ecvt (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
|
2003-03-21 00:47:25 +01:00
|
|
|
{
|
2009-11-01 18:59:20 +01:00
|
|
|
int prec, len;
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2011-08-02 22:20:32 +02:00
|
|
|
/* FIXME: check better for overflow (native supports over 300 chars) */
|
2009-04-13 09:06:41 +02:00
|
|
|
ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
|
|
|
|
* 4 for exponent and one for
|
|
|
|
* terminating '\0' */
|
2003-03-21 00:47:25 +01:00
|
|
|
if (!data->efcvt_buffer)
|
|
|
|
data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
|
|
|
|
|
2009-04-13 09:06:41 +02:00
|
|
|
if( number < 0) {
|
|
|
|
*sign = TRUE;
|
|
|
|
number = -number;
|
|
|
|
} else
|
|
|
|
*sign = FALSE;
|
|
|
|
/* handle cases with zero ndigits or less */
|
|
|
|
prec = ndigits;
|
|
|
|
if( prec < 1) prec = 2;
|
2020-06-08 17:20:39 +02:00
|
|
|
len = MSVCRT__snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
|
2009-04-13 09:06:41 +02:00
|
|
|
/* take the decimal "point away */
|
|
|
|
if( prec != 1)
|
2009-11-01 18:59:20 +01:00
|
|
|
memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
|
2009-04-13 09:06:41 +02:00
|
|
|
/* take the exponential "e" out */
|
|
|
|
data->efcvt_buffer[ prec] = '\0';
|
|
|
|
/* read the exponent */
|
2020-11-18 16:04:34 +01:00
|
|
|
MSVCRT_sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
|
2009-04-13 09:06:41 +02:00
|
|
|
(*decpt)++;
|
|
|
|
/* adjust for some border cases */
|
|
|
|
if( data->efcvt_buffer[0] == '0')/* value is zero */
|
|
|
|
*decpt = 0;
|
|
|
|
/* handle cases with zero ndigits or less */
|
|
|
|
if( ndigits < 1){
|
|
|
|
if( data->efcvt_buffer[ 0] >= '5')
|
|
|
|
(*decpt)++;
|
|
|
|
data->efcvt_buffer[ 0] = '\0';
|
|
|
|
}
|
|
|
|
TRACE("out=\"%s\"\n",data->efcvt_buffer);
|
2003-03-21 00:47:25 +01:00
|
|
|
return data->efcvt_buffer;
|
|
|
|
}
|
|
|
|
|
2010-12-10 14:46:36 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ecvt_s (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
int CDECL MSVCRT__ecvt_s( char *buffer, size_t length, double number, int ndigits, int *decpt, int *sign )
|
2010-12-10 14:46:36 +01:00
|
|
|
{
|
|
|
|
int prec, len;
|
|
|
|
char *result;
|
|
|
|
const char infret[] = "1#INF";
|
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!MSVCRT_CHECK_PMT(buffer != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(decpt != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(sign != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT_ERR( length > 2, ERANGE )) return ERANGE;
|
|
|
|
if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, ERANGE )) return ERANGE;
|
2010-12-10 14:46:36 +01:00
|
|
|
|
|
|
|
/* special case - inf */
|
|
|
|
if(number == HUGE_VAL || number == -HUGE_VAL)
|
|
|
|
{
|
|
|
|
memset(buffer, '0', ndigits);
|
|
|
|
memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
|
|
|
|
buffer[ndigits] = '\0';
|
|
|
|
(*decpt) = 1;
|
|
|
|
if(number == -HUGE_VAL)
|
|
|
|
(*sign) = 1;
|
|
|
|
else
|
|
|
|
(*sign) = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-30 20:33:06 +02:00
|
|
|
/* handle cases with zero ndigits or less */
|
|
|
|
prec = ndigits;
|
|
|
|
if( prec < 1) prec = 2;
|
2011-10-21 01:44:45 +02:00
|
|
|
result = MSVCRT_malloc(prec + 7);
|
2010-12-10 14:46:36 +01:00
|
|
|
|
|
|
|
if( number < 0) {
|
|
|
|
*sign = TRUE;
|
|
|
|
number = -number;
|
|
|
|
} else
|
|
|
|
*sign = FALSE;
|
2020-06-08 17:20:39 +02:00
|
|
|
len = MSVCRT__snprintf(result, prec + 7, "%.*le", prec - 1, number);
|
2010-12-10 14:46:36 +01:00
|
|
|
/* take the decimal "point away */
|
|
|
|
if( prec != 1)
|
|
|
|
memmove( result + 1, result + 2, len - 1 );
|
|
|
|
/* take the exponential "e" out */
|
|
|
|
result[ prec] = '\0';
|
|
|
|
/* read the exponent */
|
2020-11-18 16:04:34 +01:00
|
|
|
MSVCRT_sscanf( result + prec + 1, "%d", decpt);
|
2010-12-10 14:46:36 +01:00
|
|
|
(*decpt)++;
|
|
|
|
/* adjust for some border cases */
|
|
|
|
if( result[0] == '0')/* value is zero */
|
|
|
|
*decpt = 0;
|
|
|
|
/* handle cases with zero ndigits or less */
|
|
|
|
if( ndigits < 1){
|
|
|
|
if( result[ 0] >= '5')
|
|
|
|
(*decpt)++;
|
|
|
|
result[ 0] = '\0';
|
|
|
|
}
|
|
|
|
memcpy( buffer, result, max(ndigits + 1, 1) );
|
|
|
|
MSVCRT_free( result );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-21 00:47:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* _fcvt (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
|
2003-03-21 00:47:25 +01:00
|
|
|
{
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2007-09-24 21:10:36 +02:00
|
|
|
int stop, dec1, dec2;
|
|
|
|
char *ptr1, *ptr2, *first;
|
|
|
|
char buf[80]; /* ought to be enough */
|
2020-08-24 22:01:30 +02:00
|
|
|
char decimal_separator = get_locinfo()->lconv->decimal_point[0];
|
2003-03-21 00:47:25 +01:00
|
|
|
|
|
|
|
if (!data->efcvt_buffer)
|
|
|
|
data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
|
|
|
|
|
2007-09-24 21:10:36 +02:00
|
|
|
if (number < 0)
|
|
|
|
{
|
|
|
|
*sign = 1;
|
|
|
|
number = -number;
|
|
|
|
} else *sign = 0;
|
|
|
|
|
2020-06-08 17:20:39 +02:00
|
|
|
stop = MSVCRT__snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
|
2007-09-24 21:10:36 +02:00
|
|
|
ptr1 = buf;
|
|
|
|
ptr2 = data->efcvt_buffer;
|
|
|
|
first = NULL;
|
|
|
|
dec1 = 0;
|
|
|
|
dec2 = 0;
|
|
|
|
|
|
|
|
/* For numbers below the requested resolution, work out where
|
|
|
|
the decimal point will be rather than finding it in the string */
|
|
|
|
if (number < 1.0 && number > 0.0) {
|
2020-11-18 16:01:52 +01:00
|
|
|
dec2 = MSVCRT_log10(number + 1e-10);
|
2007-09-24 21:10:36 +02:00
|
|
|
if (-dec2 <= ndigits) dec2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If requested digits is zero or less, we will need to truncate
|
|
|
|
* the returned string */
|
|
|
|
if (ndigits < 1) {
|
2017-02-19 15:17:57 +01:00
|
|
|
stop += ndigits;
|
2007-09-24 21:10:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
|
2020-08-24 22:01:30 +02:00
|
|
|
while (*ptr1 != '\0' && *ptr1 != decimal_separator) {
|
2007-09-24 21:10:36 +02:00
|
|
|
if (!first) first = ptr2;
|
|
|
|
if ((ptr1 - buf) < stop) {
|
|
|
|
*ptr2++ = *ptr1++;
|
|
|
|
} else {
|
|
|
|
ptr1++;
|
|
|
|
}
|
|
|
|
dec1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ndigits > 0) {
|
|
|
|
ptr1++;
|
|
|
|
if (!first) {
|
|
|
|
while (*ptr1 == '0') { /* Process leading zeroes */
|
|
|
|
*ptr2++ = *ptr1++;
|
|
|
|
dec1--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*ptr1 != '\0') {
|
|
|
|
if (!first) first = ptr2;
|
|
|
|
*ptr2++ = *ptr1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr2 = '\0';
|
|
|
|
|
|
|
|
/* We never found a non-zero digit, then our number is either
|
|
|
|
* smaller than the requested precision, or 0.0 */
|
|
|
|
if (!first) {
|
|
|
|
if (number > 0.0) {
|
|
|
|
first = ptr2;
|
|
|
|
} else {
|
|
|
|
first = data->efcvt_buffer;
|
|
|
|
dec1 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*decpt = dec2 ? dec2 : dec1;
|
|
|
|
return first;
|
2003-03-21 00:47:25 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 18:47:34 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* _fcvt_s (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
int CDECL MSVCRT__fcvt_s(char* outbuffer, size_t size, double number, int ndigits, int *decpt, int *sign)
|
2011-01-29 18:47:34 +01:00
|
|
|
{
|
|
|
|
int stop, dec1, dec2;
|
|
|
|
char *ptr1, *ptr2, *first;
|
|
|
|
char buf[80]; /* ought to be enough */
|
2020-08-24 22:01:30 +02:00
|
|
|
char decimal_separator = get_locinfo()->lconv->decimal_point[0];
|
2011-01-29 18:47:34 +01:00
|
|
|
|
|
|
|
if (!outbuffer || !decpt || !sign || size == 0)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EINVAL;
|
|
|
|
return EINVAL;
|
2011-01-29 18:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (number < 0)
|
|
|
|
{
|
|
|
|
*sign = 1;
|
|
|
|
number = -number;
|
|
|
|
} else *sign = 0;
|
|
|
|
|
2020-06-08 17:20:39 +02:00
|
|
|
stop = MSVCRT__snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
|
2011-01-29 18:47:34 +01:00
|
|
|
ptr1 = buf;
|
|
|
|
ptr2 = outbuffer;
|
|
|
|
first = NULL;
|
|
|
|
dec1 = 0;
|
|
|
|
dec2 = 0;
|
|
|
|
|
|
|
|
/* For numbers below the requested resolution, work out where
|
|
|
|
the decimal point will be rather than finding it in the string */
|
|
|
|
if (number < 1.0 && number > 0.0) {
|
2020-11-18 16:01:52 +01:00
|
|
|
dec2 = MSVCRT_log10(number + 1e-10);
|
2011-01-29 18:47:34 +01:00
|
|
|
if (-dec2 <= ndigits) dec2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If requested digits is zero or less, we will need to truncate
|
|
|
|
* the returned string */
|
|
|
|
if (ndigits < 1) {
|
2017-02-19 15:17:57 +01:00
|
|
|
stop += ndigits;
|
2011-01-29 18:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
|
2020-08-24 22:01:30 +02:00
|
|
|
while (*ptr1 != '\0' && *ptr1 != decimal_separator) {
|
2011-01-29 18:47:34 +01:00
|
|
|
if (!first) first = ptr2;
|
|
|
|
if ((ptr1 - buf) < stop) {
|
|
|
|
if (size > 1) {
|
|
|
|
*ptr2++ = *ptr1++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ptr1++;
|
|
|
|
}
|
|
|
|
dec1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ndigits > 0) {
|
|
|
|
ptr1++;
|
|
|
|
if (!first) {
|
|
|
|
while (*ptr1 == '0') { /* Process leading zeroes */
|
|
|
|
if (number == 0.0 && size > 1) {
|
|
|
|
*ptr2++ = '0';
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
ptr1++;
|
|
|
|
dec1--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*ptr1 != '\0') {
|
|
|
|
if (!first) first = ptr2;
|
|
|
|
if (size > 1) {
|
|
|
|
*ptr2++ = *ptr1++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr2 = '\0';
|
|
|
|
|
|
|
|
/* We never found a non-zero digit, then our number is either
|
|
|
|
* smaller than the requested precision, or 0.0 */
|
|
|
|
if (!first && (number <= 0.0))
|
|
|
|
dec1 = 0;
|
|
|
|
|
|
|
|
*decpt = dec2 ? dec2 : dec1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-21 00:47:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* _gcvt (MSVCRT.@)
|
|
|
|
*/
|
2014-04-16 16:15:07 +02:00
|
|
|
char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
|
2003-03-21 00:47:25 +01:00
|
|
|
{
|
2010-08-27 01:46:35 +02:00
|
|
|
if(!buff) {
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EINVAL;
|
2010-08-27 01:46:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ndigit < 0) {
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
2010-08-27 01:46:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_sprintf(buff, "%.*g", ndigit, number);
|
2003-03-21 00:47:25 +01:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2010-08-27 01:46:35 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* _gcvt_s (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
int CDECL MSVCRT__gcvt_s(char *buff, size_t size, double number, int digits)
|
2010-08-27 01:46:35 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if(!buff) {
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EINVAL;
|
|
|
|
return EINVAL;
|
2010-08-27 01:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( digits<0 || digits>=size) {
|
|
|
|
if(size)
|
|
|
|
buff[0] = '\0';
|
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
|
|
|
return ERANGE;
|
2010-08-27 01:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
len = MSVCRT__scprintf("%.*g", digits, number);
|
|
|
|
if(len > size) {
|
|
|
|
buff[0] = '\0';
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = ERANGE;
|
|
|
|
return ERANGE;
|
2010-08-27 01:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_sprintf(buff, "%.*g", digits, number);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include <stdlib.h> /* div_t, ldiv_t */
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* div (MSVCRT.@)
|
|
|
|
* VERSION
|
|
|
|
* [i386] Windows binary compatible - returns the struct in eax/edx.
|
|
|
|
*/
|
|
|
|
#ifdef __i386__
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned __int64 CDECL MSVCRT_div(int num, int denom)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-07-22 12:30:16 +02:00
|
|
|
union {
|
2020-11-20 12:35:52 +01:00
|
|
|
div_t div;
|
2020-07-22 12:30:16 +02:00
|
|
|
unsigned __int64 uint64;
|
|
|
|
} ret;
|
|
|
|
|
|
|
|
ret.div.quot = num / denom;
|
|
|
|
ret.div.rem = num % denom;
|
|
|
|
return ret.uint64;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*********************************************************************
|
|
|
|
* div (MSVCRT.@)
|
|
|
|
* VERSION
|
|
|
|
* [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
|
|
|
|
*/
|
2020-11-20 12:35:52 +01:00
|
|
|
div_t CDECL MSVCRT_div(int num, int denom)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-20 12:35:52 +01:00
|
|
|
div_t ret;
|
2002-05-17 01:08:01 +02:00
|
|
|
|
2020-07-22 12:30:16 +02:00
|
|
|
ret.quot = num / denom;
|
|
|
|
ret.rem = num % denom;
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
#endif /* ifdef __i386__ */
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ldiv (MSVCRT.@)
|
|
|
|
* VERSION
|
|
|
|
* [i386] Windows binary compatible - returns the struct in eax/edx.
|
|
|
|
*/
|
|
|
|
#ifdef __i386__
|
2020-11-27 14:17:05 +01:00
|
|
|
unsigned __int64 CDECL MSVCRT_ldiv(__msvcrt_long num, __msvcrt_long denom)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-07-22 12:30:16 +02:00
|
|
|
union {
|
2020-11-20 12:35:52 +01:00
|
|
|
ldiv_t ldiv;
|
2020-07-22 12:30:16 +02:00
|
|
|
unsigned __int64 uint64;
|
|
|
|
} ret;
|
|
|
|
|
|
|
|
ret.ldiv.quot = num / denom;
|
|
|
|
ret.ldiv.rem = num % denom;
|
|
|
|
return ret.uint64;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*********************************************************************
|
|
|
|
* ldiv (MSVCRT.@)
|
|
|
|
* VERSION
|
|
|
|
* [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
ldiv_t CDECL MSVCRT_ldiv(__msvcrt_long num, __msvcrt_long denom)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-20 12:35:52 +01:00
|
|
|
ldiv_t ret;
|
2002-05-17 01:08:01 +02:00
|
|
|
|
2020-07-22 12:30:16 +02:00
|
|
|
ret.quot = num / denom;
|
|
|
|
ret.rem = num % denom;
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
#endif /* ifdef __i386__ */
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=100
|
2017-02-20 17:43:32 +01:00
|
|
|
/*********************************************************************
|
2017-12-22 18:38:56 +01:00
|
|
|
* lldiv (MSVCR100.@)
|
2017-02-20 17:43:32 +01:00
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
lldiv_t CDECL MSVCRT_lldiv(__int64 num, __int64 denom)
|
2017-02-20 17:43:32 +01:00
|
|
|
{
|
2020-11-20 12:35:52 +01:00
|
|
|
lldiv_t ret;
|
2020-07-11 20:02:45 +02:00
|
|
|
|
|
|
|
ret.quot = num / denom;
|
|
|
|
ret.rem = num % denom;
|
2017-02-20 17:43:32 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif
|
2017-02-20 17:43:32 +01:00
|
|
|
|
2009-08-24 12:50:46 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _adjust_fdiv (MSVCRT.@)
|
|
|
|
* Used by the MSVC compiler to work around the Pentium FDIV bug.
|
|
|
|
*/
|
|
|
|
int MSVCRT__adjust_fdiv = 0;
|
|
|
|
|
2001-02-12 04:45:09 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdiv_m16i (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdiv_m16i( short arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdiv_m32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdiv_m32( unsigned int arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdiv_m32i (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdiv_m32i( int arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdiv_m64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdiv_r (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _adj_fdiv_r(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdivr_m16i (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdivr_m16i( short arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdivr_m32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdivr_m32( unsigned int arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdivr_m32i (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdivr_m32i( int arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fdivr_m64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2004-05-13 01:22:36 +02:00
|
|
|
void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fpatan (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _adj_fpatan(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fprem (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _adj_fprem(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fprem1 (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _adj_fprem1(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _adj_fptan (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _adj_fptan(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _safe_fdiv (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _safe_fdiv(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _safe_fdivr (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _safe_fdivr(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _safe_fprem (MSVCRT.@)
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _safe_fprem(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _safe_fprem1 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* This function is likely to have the wrong number of arguments.
|
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* I _think_ this function is intended to work around the Pentium
|
|
|
|
* fdiv bug.
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _safe_fprem1(void)
|
2001-02-12 04:45:09 +01:00
|
|
|
{
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("(): stub\n");
|
2001-02-12 04:45:09 +01:00
|
|
|
}
|
2009-08-24 12:50:46 +02:00
|
|
|
|
2011-01-26 20:48:44 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_acos (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_acos(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_acos( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_acosf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_acosf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_acosf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_asin (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_asin(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_asin( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_asinf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_asinf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_asinf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_atan (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_atan(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_atan( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_atan2 (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_atan2(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d1, d2;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d1 = MSVCRT_atan2( d1, d2 );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_atanf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_atanf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_atanf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_cos (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_cos(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_cos( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_cosf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_cosf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_cosf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_exp (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_exp(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_exp( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_expf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_expf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_expf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_log (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_log(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_log( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_log10 (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_log10(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_log10( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_log10f (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_log10f(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_log10f( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_logf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_logf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_logf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_pow (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_pow(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d1, d2;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d1 = MSVCRT_pow( d1, d2 );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_powf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_powf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f1, f2;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f1 = MSVCRT_powf( f1, f2 );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_sin (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_sin(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_sin( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_sinf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_sinf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_sinf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_tan (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_tan(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_tan( d );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_tanf (MSVCRT.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_tanf(void)
|
2011-01-26 20:48:44 +01:00
|
|
|
{
|
|
|
|
float f;
|
|
|
|
__asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
|
2020-11-18 16:01:52 +01:00
|
|
|
f = MSVCRT_tanf( f );
|
2011-01-26 20:48:44 +01:00
|
|
|
__asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:32:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* __libm_sse2_sqrt_precise (MSVCR110.@)
|
|
|
|
*/
|
2015-12-22 13:08:58 +01:00
|
|
|
void __cdecl MSVCRT___libm_sse2_sqrt_precise(void)
|
2014-01-07 15:47:34 +01:00
|
|
|
{
|
|
|
|
double d;
|
2014-05-19 18:49:02 +02:00
|
|
|
__asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
|
2020-11-18 16:01:52 +01:00
|
|
|
d = MSVCRT_sqrt( d );
|
2014-05-19 18:49:02 +02:00
|
|
|
__asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
|
2014-01-07 15:47:34 +01:00
|
|
|
}
|
|
|
|
|
2009-08-24 12:50:46 +02:00
|
|
|
#endif /* __i386__ */
|
2014-12-08 13:35:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* cbrt (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_cbrt(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->cbrt( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* cbrtf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_cbrtf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->cbrtf( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* cbrtl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_cbrt(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* exp2 (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_exp2(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->exp2( x );
|
2020-11-30 14:37:27 +01:00
|
|
|
if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-25 08:52:27 +02:00
|
|
|
return ret;
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* exp2f (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_exp2f(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->exp2f( x );
|
2020-11-30 14:37:27 +01:00
|
|
|
if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-25 08:52:27 +02:00
|
|
|
return ret;
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* exp2l (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_exp2(x);
|
|
|
|
}
|
|
|
|
|
2017-07-14 07:14:20 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* expm1 (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_expm1(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
double ret = unix_funcs->expm1( x );
|
2020-11-30 14:37:27 +01:00
|
|
|
if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-14 07:14:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* expm1f (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_expm1f(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
float ret = unix_funcs->expm1f( x );
|
2020-11-30 14:37:27 +01:00
|
|
|
if (isfinite(x) && !isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-14 07:14:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* expm1l (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_expm1l(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_expm1(x);
|
|
|
|
}
|
|
|
|
|
2017-07-18 06:33:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* log1p (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_log1p(double x)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if (x < -1) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (x == -1) *MSVCRT__errno() = ERANGE;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->log1p( x );
|
2017-07-18 06:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* log1pf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_log1pf(float x)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if (x < -1) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (x == -1) *MSVCRT__errno() = ERANGE;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->log1pf( x );
|
2017-07-18 06:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* log1pl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_log1pl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_log1p(x);
|
|
|
|
}
|
|
|
|
|
2014-12-08 13:35:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* log2 (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_log2(double x)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if (x < 0) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (x == 0) *MSVCRT__errno() = ERANGE;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->log2( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* log2f (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_log2f(float x)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if (x < 0) *MSVCRT__errno() = EDOM;
|
|
|
|
else if (x == 0) *MSVCRT__errno() = ERANGE;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->log2f( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* log2l (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_log2(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* rint (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_rint(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->rint(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* rintf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_rintf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->rintf(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* rintl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_rint(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lrint (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lrint(double x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lrint( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lrintf (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lrintf(float x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lrintf( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lrintl (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lrintl(LDOUBLE x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
|
|
|
return MSVCR120_lrint(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* llrint (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llrint(double x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->llrint( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* llrintf (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llrintf(float x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->llrintf( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* rintl (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llrintl(LDOUBLE x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
|
|
|
return MSVCR120_llrint(x);
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
|
2014-12-08 13:35:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* round (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_round(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->round(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* roundf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_roundf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->roundf(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* roundl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_round(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lround (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lround(double x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lround( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lroundf (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lroundf(float x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lroundf( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lroundl (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__msvcrt_long CDECL MSVCR120_lroundl(LDOUBLE x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
|
|
|
return MSVCR120_lround(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* llround (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llround(double x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->llround( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* llroundf (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llroundf(float x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->llroundf( x );
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* roundl (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
__int64 CDECL MSVCR120_llroundl(LDOUBLE x)
|
2014-12-08 13:35:25 +01:00
|
|
|
{
|
|
|
|
return MSVCR120_llround(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* trunc (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_trunc(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->trunc(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* truncf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_truncf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->truncf(x);
|
2014-12-08 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* truncl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_trunc(x);
|
|
|
|
}
|
2014-12-09 07:43:07 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _dclass (MSVCR120.@)
|
2020-11-16 12:09:43 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/__fpclassify.c
|
2014-12-09 07:43:07 +01:00
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__dclass(double x)
|
|
|
|
{
|
2020-11-16 12:09:43 +01:00
|
|
|
union { double f; UINT64 i; } u = { x };
|
|
|
|
int e = u.i >> 52 & 0x7ff;
|
|
|
|
|
|
|
|
if (!e) return u.i << 1 ? MSVCRT_FP_SUBNORMAL : MSVCRT_FP_ZERO;
|
|
|
|
if (e == 0x7ff) return (u.i << 12) ? MSVCRT_FP_NAN : MSVCRT_FP_INFINITE;
|
|
|
|
return MSVCRT_FP_NORMAL;
|
2014-12-09 07:43:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fdclass (MSVCR120.@)
|
2020-11-16 12:09:43 +01:00
|
|
|
*
|
|
|
|
* Copied from musl: src/math/__fpclassifyf.c
|
2014-12-09 07:43:07 +01:00
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__fdclass(float x)
|
|
|
|
{
|
2020-11-16 12:09:43 +01:00
|
|
|
union { float f; UINT32 i; } u = { x };
|
|
|
|
int e = u.i >> 23 & 0xff;
|
|
|
|
|
|
|
|
if (!e) return u.i << 1 ? MSVCRT_FP_SUBNORMAL : MSVCRT_FP_ZERO;
|
|
|
|
if (e == 0xff) return u.i << 9 ? MSVCRT_FP_NAN : MSVCRT_FP_INFINITE;
|
|
|
|
return MSVCRT_FP_NORMAL;
|
2014-12-09 07:43:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ldclass (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__ldclass(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120__dclass(x);
|
|
|
|
}
|
2015-01-07 15:16:23 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _dtest (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__dtest(double *x)
|
|
|
|
{
|
|
|
|
return MSVCR120__dclass(*x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fdtest (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__fdtest(float *x)
|
|
|
|
{
|
2020-11-16 12:09:43 +01:00
|
|
|
return MSVCR120__fdclass(*x);
|
2015-01-07 15:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ldtest (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
short CDECL MSVCR120__ldtest(LDOUBLE *x)
|
|
|
|
{
|
|
|
|
return MSVCR120__dclass(*x);
|
|
|
|
}
|
2015-05-26 14:54:40 +02:00
|
|
|
|
2015-05-21 18:25:48 +02:00
|
|
|
/*********************************************************************
|
2017-07-12 18:04:40 +02:00
|
|
|
* erf (MSVCR120.@)
|
2015-05-21 18:25:48 +02:00
|
|
|
*/
|
2017-07-12 18:04:40 +02:00
|
|
|
double CDECL MSVCR120_erf(double x)
|
2015-05-21 18:25:48 +02:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->erf( x );
|
2015-05-21 18:25:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2017-07-12 18:04:40 +02:00
|
|
|
* erff (MSVCR120.@)
|
2015-05-21 18:25:48 +02:00
|
|
|
*/
|
2017-07-12 18:04:40 +02:00
|
|
|
float CDECL MSVCR120_erff(float x)
|
2015-05-21 18:25:48 +02:00
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->erff( x );
|
2015-05-21 18:25:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* erfl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_erfl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_erf(x);
|
|
|
|
}
|
|
|
|
|
2017-07-14 07:14:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* erfc (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_erfc(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->erfc( x );
|
2017-07-14 07:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* erfcf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_erfcf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->erfcf( x );
|
2017-07-14 07:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* erfcl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_erfcl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_erfc(x);
|
|
|
|
}
|
|
|
|
|
2015-05-26 14:54:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fmaxf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_fmaxf(float x, float y)
|
|
|
|
{
|
2018-09-26 05:03:02 +02:00
|
|
|
if(isnan(x))
|
2015-05-26 14:54:40 +02:00
|
|
|
return y;
|
2018-09-26 05:03:02 +02:00
|
|
|
if(isnan(y))
|
2015-05-26 14:54:40 +02:00
|
|
|
return x;
|
|
|
|
if(x==0 && y==0)
|
|
|
|
return signbit(x) ? y : x;
|
|
|
|
return x<y ? y : x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* fmax (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_fmax(double x, double y)
|
|
|
|
{
|
|
|
|
if(isnan(x))
|
|
|
|
return y;
|
|
|
|
if(isnan(y))
|
|
|
|
return x;
|
|
|
|
if(x==0 && y==0)
|
|
|
|
return signbit(x) ? y : x;
|
|
|
|
return x<y ? y : x;
|
|
|
|
}
|
2015-05-26 14:54:49 +02:00
|
|
|
|
2019-07-30 23:08:52 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fdimf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_fdimf(float x, float y)
|
|
|
|
{
|
|
|
|
if(isnan(x))
|
|
|
|
return x;
|
|
|
|
if(isnan(y))
|
|
|
|
return y;
|
|
|
|
return x>y ? x-y : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* fdim (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_fdim(double x, double y)
|
|
|
|
{
|
|
|
|
if(isnan(x))
|
|
|
|
return x;
|
|
|
|
if(isnan(y))
|
|
|
|
return y;
|
|
|
|
return x>y ? x-y : 0;
|
|
|
|
}
|
|
|
|
|
2015-05-26 14:54:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _fdsign (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCR120__fdsign(float x)
|
|
|
|
{
|
2020-11-16 12:21:16 +01:00
|
|
|
union { float f; UINT32 i; } u = { x };
|
|
|
|
return (u.i >> 16) & 0x8000;
|
2015-05-26 14:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _dsign (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCR120__dsign(double x)
|
|
|
|
{
|
2020-11-16 12:21:16 +01:00
|
|
|
union { double f; UINT64 i; } u = { x };
|
|
|
|
return (u.i >> 48) & 0x8000;
|
2015-05-26 14:54:49 +02:00
|
|
|
}
|
2015-09-12 14:29:00 +02:00
|
|
|
|
2016-01-18 12:57:39 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _dpcomp (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCR120__dpcomp(double x, double y)
|
|
|
|
{
|
|
|
|
if(isnan(x) || isnan(y))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(x == y) return 2;
|
|
|
|
return x < y ? 1 : 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fdpcomp (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCR120__fdpcomp(float x, float y)
|
|
|
|
{
|
|
|
|
return MSVCR120__dpcomp(x, y);
|
|
|
|
}
|
|
|
|
|
2015-09-12 14:29:00 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* fminf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_fminf(float x, float y)
|
|
|
|
{
|
2018-09-26 05:03:02 +02:00
|
|
|
if(isnan(x))
|
2015-09-12 14:29:00 +02:00
|
|
|
return y;
|
2018-09-26 05:03:02 +02:00
|
|
|
if(isnan(y))
|
2015-09-12 14:29:00 +02:00
|
|
|
return x;
|
|
|
|
if(x==0 && y==0)
|
|
|
|
return signbit(x) ? x : y;
|
|
|
|
return x<y ? x : y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* fmin (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_fmin(double x, double y)
|
|
|
|
{
|
|
|
|
if(isnan(x))
|
|
|
|
return y;
|
|
|
|
if(isnan(y))
|
|
|
|
return x;
|
|
|
|
if(x==0 && y==0)
|
|
|
|
return signbit(x) ? x : y;
|
|
|
|
return x<y ? x : y;
|
|
|
|
}
|
2016-03-28 21:00:35 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* asinh (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_asinh(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->asinh( x );
|
2016-03-28 21:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* asinhf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_asinhf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->asinhf( x );
|
2016-03-28 21:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* asinhl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_asinhl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_asinh(x);
|
2017-07-12 18:05:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* acosh (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_acosh(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
if (x < 1)
|
|
|
|
{
|
2020-11-20 12:51:23 +01:00
|
|
|
fenv_t env;
|
2017-07-12 18:05:09 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2017-07-12 18:05:09 +02:00
|
|
|
MSVCRT_fegetenv(&env);
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INVALID;
|
2017-07-12 18:05:09 +02:00
|
|
|
MSVCRT_fesetenv(&env);
|
|
|
|
return NAN;
|
|
|
|
}
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->acosh( x );
|
2017-07-12 18:05:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* acoshf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_acoshf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
if (x < 1)
|
|
|
|
{
|
2020-11-20 12:51:23 +01:00
|
|
|
fenv_t env;
|
2017-07-12 18:05:09 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
MSVCRT_fegetenv(&env);
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INVALID;
|
2020-11-18 16:14:50 +01:00
|
|
|
MSVCRT_fesetenv(&env);
|
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
return unix_funcs->acoshf( x );
|
2017-07-12 18:05:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* acoshl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_acoshl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_acosh(x);
|
2017-07-12 18:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atanh (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_atanh(double x)
|
|
|
|
{
|
|
|
|
double ret;
|
|
|
|
|
|
|
|
if (x > 1 || x < -1) {
|
2020-11-20 12:51:23 +01:00
|
|
|
fenv_t env;
|
2017-07-12 18:05:19 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2017-07-12 18:05:19 +02:00
|
|
|
|
|
|
|
/* on Linux atanh returns -NAN in this case */
|
|
|
|
MSVCRT_fegetenv(&env);
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INVALID;
|
2017-07-12 18:05:19 +02:00
|
|
|
MSVCRT_fesetenv(&env);
|
|
|
|
return NAN;
|
|
|
|
}
|
2020-11-18 16:14:50 +01:00
|
|
|
ret = unix_funcs->atanh( x );
|
2017-07-12 18:05:19 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-12 18:05:19 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atanhf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_atanhf(float x)
|
|
|
|
{
|
2017-07-24 08:40:33 +02:00
|
|
|
float ret;
|
2017-07-12 18:05:19 +02:00
|
|
|
|
|
|
|
if (x > 1 || x < -1) {
|
2020-11-20 12:51:23 +01:00
|
|
|
fenv_t env;
|
2017-07-12 18:05:19 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
*MSVCRT__errno() = EDOM;
|
2017-07-12 18:05:19 +02:00
|
|
|
|
|
|
|
MSVCRT_fegetenv(&env);
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INVALID;
|
2017-07-12 18:05:19 +02:00
|
|
|
MSVCRT_fesetenv(&env);
|
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:14:50 +01:00
|
|
|
ret = unix_funcs->atanh( x );
|
2017-07-12 18:05:19 +02:00
|
|
|
|
2020-11-30 14:37:27 +01:00
|
|
|
if (!isfinite(ret)) *MSVCRT__errno() = ERANGE;
|
2017-07-12 18:05:19 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atanhl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_atanhl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_atanh(x);
|
2016-03-28 21:00:35 +02:00
|
|
|
}
|
2016-03-28 22:44:31 +02:00
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif /* _MSVCR_VER>=120 */
|
|
|
|
|
2016-03-28 22:44:31 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _scalb (MSVCRT.@)
|
|
|
|
* scalbn (MSVCR120.@)
|
|
|
|
* scalbln (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
double CDECL MSVCRT__scalb(double num, __msvcrt_long power)
|
2016-03-28 22:44:31 +02:00
|
|
|
{
|
2017-07-25 08:52:27 +02:00
|
|
|
return MSVCRT_ldexp(num, power);
|
2016-03-28 22:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _scalbf (MSVCRT.@)
|
|
|
|
* scalbnf (MSVCR120.@)
|
|
|
|
* scalblnf (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
float CDECL MSVCRT__scalbf(float num, __msvcrt_long power)
|
2016-03-28 22:44:31 +02:00
|
|
|
{
|
2017-07-25 08:52:27 +02:00
|
|
|
return MSVCRT_ldexp(num, power);
|
2016-03-28 22:44:31 +02:00
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#if _MSVCR_VER>=120
|
|
|
|
|
2016-03-28 22:44:31 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* scalbnl (MSVCR120.@)
|
|
|
|
* scalblnl (MSVCR120.@)
|
|
|
|
*/
|
2020-11-27 14:17:05 +01:00
|
|
|
LDOUBLE CDECL MSVCR120_scalbnl(LDOUBLE num, __msvcrt_long power)
|
2016-03-28 22:44:31 +02:00
|
|
|
{
|
|
|
|
return MSVCRT__scalb(num, power);
|
|
|
|
}
|
2016-04-05 21:53:12 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* remainder (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_remainder(double x, double y)
|
|
|
|
{
|
|
|
|
/* this matches 64-bit Windows. 32-bit Windows is slightly different */
|
2020-11-30 14:37:27 +01:00
|
|
|
if(!isfinite(x)) *MSVCRT__errno() = EDOM;
|
|
|
|
if(isnan(y) || y==0.0) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->remainder( x, y );
|
2016-04-05 21:53:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* remainderf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_remainderf(float x, float y)
|
|
|
|
{
|
|
|
|
/* this matches 64-bit Windows. 32-bit Windows is slightly different */
|
2020-11-30 14:37:27 +01:00
|
|
|
if(!isfinite(x)) *MSVCRT__errno() = EDOM;
|
|
|
|
if(isnan(y) || y==0.0f) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->remainderf( x, y );
|
2016-04-05 21:53:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* remainderl (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_remainderl(LDOUBLE x, LDOUBLE y)
|
|
|
|
{
|
|
|
|
return MSVCR120_remainder(x, y);
|
|
|
|
}
|
2016-06-17 23:49:32 +02:00
|
|
|
|
2019-04-10 20:14:28 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* remquo (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_remquo(double x, double y, int *quo)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if(!isfinite(x)) *MSVCRT__errno() = EDOM;
|
|
|
|
if(isnan(y) || y==0.0) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->remquo( x, y, quo );
|
2019-04-10 20:14:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* remquof (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_remquof(float x, float y, int *quo)
|
|
|
|
{
|
2020-11-30 14:37:27 +01:00
|
|
|
if(!isfinite(x)) *MSVCRT__errno() = EDOM;
|
|
|
|
if(isnan(y) || y==0.0f) *MSVCRT__errno() = EDOM;
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->remquof( x, y, quo );
|
2019-04-10 20:14:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* remquol (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_remquol(LDOUBLE x, LDOUBLE y, int *quo)
|
|
|
|
{
|
|
|
|
return MSVCR120_remquo(x, y, quo);
|
|
|
|
}
|
|
|
|
|
2016-06-17 23:49:32 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* lgamma (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_lgamma(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lgamma( x );
|
2016-06-17 23:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lgammaf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_lgammaf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->lgammaf( x );
|
2016-06-17 23:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* lgammal (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
LDOUBLE CDECL MSVCR120_lgammal(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_lgamma(x);
|
|
|
|
}
|
2017-01-27 12:38:02 +01:00
|
|
|
|
2019-08-01 21:52:26 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* tgamma (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_tgamma(double x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->tgamma( x );
|
2019-08-01 21:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* tgammaf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_tgammaf(float x)
|
|
|
|
{
|
2020-11-18 16:14:50 +01:00
|
|
|
return unix_funcs->tgammaf( x );
|
2019-08-01 21:52:26 +02:00
|
|
|
}
|
|
|
|
|
2017-01-27 12:38:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* nan (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
double CDECL MSVCR120_nan(const char *tagp)
|
|
|
|
{
|
|
|
|
/* Windows ignores input (MSDN) */
|
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* nanf (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
float CDECL MSVCR120_nanf(const char *tagp)
|
|
|
|
{
|
|
|
|
return NAN;
|
|
|
|
}
|
2017-02-17 15:54:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _except1 (MSVCR120.@)
|
|
|
|
* TODO:
|
|
|
|
* - find meaning of ignored cw and operation bits
|
|
|
|
* - unk parameter
|
|
|
|
*/
|
|
|
|
double CDECL _except1(DWORD fpe, _FP_OPERATION_CODE op, double arg, double res, DWORD cw, void *unk)
|
|
|
|
{
|
|
|
|
ULONG_PTR exception_arg;
|
|
|
|
DWORD exception = 0;
|
2020-11-20 12:51:23 +01:00
|
|
|
fenv_t env;
|
2017-02-17 15:54:25 +01:00
|
|
|
DWORD fpword = 0;
|
|
|
|
WORD operation;
|
|
|
|
|
|
|
|
TRACE("(%x %x %lf %lf %x %p)\n", fpe, op, arg, res, cw, unk);
|
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
cw = ((cw >> 7) & 0x3f) | ((cw >> 3) & 0xc00);
|
|
|
|
#endif
|
|
|
|
operation = op << 5;
|
|
|
|
exception_arg = (ULONG_PTR)&operation;
|
|
|
|
|
|
|
|
MSVCRT_fegetenv(&env);
|
|
|
|
|
|
|
|
if (fpe & 0x1) { /* overflow */
|
|
|
|
if ((fpe == 0x1 && (cw & 0x8)) || (fpe==0x11 && (cw & 0x28))) {
|
|
|
|
/* 32-bit version also sets SW_INEXACT here */
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_OVERFLOW;
|
|
|
|
if (fpe & 0x10) env._Fe_stat |= FE_INEXACT;
|
2017-02-17 15:54:25 +01:00
|
|
|
res = signbit(res) ? -INFINITY : INFINITY;
|
|
|
|
} else {
|
|
|
|
exception = EXCEPTION_FLT_OVERFLOW;
|
|
|
|
}
|
|
|
|
} else if (fpe & 0x2) { /* underflow */
|
|
|
|
if ((fpe == 0x2 && (cw & 0x10)) || (fpe==0x12 && (cw & 0x30))) {
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_UNDERFLOW;
|
|
|
|
if (fpe & 0x10) env._Fe_stat |= FE_INEXACT;
|
2017-02-17 15:54:25 +01:00
|
|
|
res = signbit(res) ? -0.0 : 0.0;
|
|
|
|
} else {
|
|
|
|
exception = EXCEPTION_FLT_UNDERFLOW;
|
|
|
|
}
|
|
|
|
} else if (fpe & 0x4) { /* zerodivide */
|
|
|
|
if ((fpe == 0x4 && (cw & 0x4)) || (fpe==0x14 && (cw & 0x24))) {
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_DIVBYZERO;
|
|
|
|
if (fpe & 0x10) env._Fe_stat |= FE_INEXACT;
|
2017-02-17 15:54:25 +01:00
|
|
|
} else {
|
|
|
|
exception = EXCEPTION_FLT_DIVIDE_BY_ZERO;
|
|
|
|
}
|
|
|
|
} else if (fpe & 0x8) { /* invalid */
|
|
|
|
if (fpe == 0x8 && (cw & 0x1)) {
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INVALID;
|
2017-02-17 15:54:25 +01:00
|
|
|
} else {
|
|
|
|
exception = EXCEPTION_FLT_INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
} else if (fpe & 0x10) { /* inexact */
|
|
|
|
if (fpe == 0x10 && (cw & 0x20)) {
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat |= FE_INEXACT;
|
2017-02-17 15:54:25 +01:00
|
|
|
} else {
|
|
|
|
exception = EXCEPTION_FLT_INEXACT_RESULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exception)
|
2020-11-20 12:51:23 +01:00
|
|
|
env._Fe_stat = 0;
|
2017-02-17 15:54:25 +01:00
|
|
|
MSVCRT_fesetenv(&env);
|
|
|
|
if (exception)
|
|
|
|
RaiseException(exception, 0, 1, &exception_arg);
|
|
|
|
|
|
|
|
if (cw & 0x1) fpword |= MSVCRT__EM_INVALID;
|
|
|
|
if (cw & 0x2) fpword |= MSVCRT__EM_DENORMAL;
|
|
|
|
if (cw & 0x4) fpword |= MSVCRT__EM_ZERODIVIDE;
|
|
|
|
if (cw & 0x8) fpword |= MSVCRT__EM_OVERFLOW;
|
|
|
|
if (cw & 0x10) fpword |= MSVCRT__EM_UNDERFLOW;
|
|
|
|
if (cw & 0x20) fpword |= MSVCRT__EM_INEXACT;
|
|
|
|
switch (cw & 0xc00)
|
|
|
|
{
|
|
|
|
case 0xc00: fpword |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
|
|
|
|
case 0x800: fpword |= MSVCRT__RC_UP; break;
|
|
|
|
case 0x400: fpword |= MSVCRT__RC_DOWN; break;
|
|
|
|
}
|
|
|
|
switch (cw & 0x300)
|
|
|
|
{
|
|
|
|
case 0x0: fpword |= MSVCRT__PC_24; break;
|
|
|
|
case 0x200: fpword |= MSVCRT__PC_53; break;
|
|
|
|
case 0x300: fpword |= MSVCRT__PC_64; break;
|
|
|
|
}
|
|
|
|
if (cw & 0x1000) fpword |= MSVCRT__IC_AFFINE;
|
|
|
|
_control87(fpword, 0xffffffff);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-12-22 18:38:56 +01:00
|
|
|
|
2018-10-01 19:50:39 +02:00
|
|
|
_Dcomplex* CDECL MSVCR120__Cbuild(_Dcomplex *ret, double r, double i)
|
|
|
|
{
|
|
|
|
ret->x = r;
|
|
|
|
ret->y = i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-01 19:50:45 +02:00
|
|
|
double CDECL MSVCR120_creal(_Dcomplex z)
|
|
|
|
{
|
|
|
|
return z.x;
|
|
|
|
}
|
|
|
|
|
2020-11-17 09:59:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ilogb (MSVCR120.@)
|
|
|
|
*
|
|
|
|
* Copied from musl: src/math/ilogb.c
|
|
|
|
*/
|
2019-02-28 21:08:13 +01:00
|
|
|
int CDECL MSVCR120_ilogb(double x)
|
|
|
|
{
|
2020-11-17 09:59:54 +01:00
|
|
|
union { double f; UINT64 i; } u = { x };
|
|
|
|
int e = u.i >> 52 & 0x7ff;
|
2019-02-28 21:08:13 +01:00
|
|
|
|
2020-11-17 09:59:54 +01:00
|
|
|
if (!e)
|
|
|
|
{
|
|
|
|
u.i <<= 12;
|
2020-11-27 14:17:01 +01:00
|
|
|
if (u.i == 0) return FP_ILOGB0;
|
2020-11-17 09:59:54 +01:00
|
|
|
/* subnormal x */
|
|
|
|
for (e = -0x3ff; u.i >> 63 == 0; e--, u.i <<= 1);
|
|
|
|
return e;
|
|
|
|
}
|
2020-11-27 14:17:01 +01:00
|
|
|
if (e == 0x7ff) return u.i << 12 ? FP_ILOGBNAN : INT_MAX;
|
2020-11-17 09:59:54 +01:00
|
|
|
return e - 0x3ff;
|
2019-02-28 21:08:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 09:59:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ilogbf (MSVCR120.@)
|
|
|
|
*
|
|
|
|
* Copied from musl: src/math/ilogbf.c
|
|
|
|
*/
|
2019-02-28 21:08:13 +01:00
|
|
|
int CDECL MSVCR120_ilogbf(float x)
|
|
|
|
{
|
2020-11-17 09:59:54 +01:00
|
|
|
union { float f; UINT32 i; } u = { x };
|
|
|
|
int e = u.i >> 23 & 0xff;
|
2019-02-28 21:08:13 +01:00
|
|
|
|
2020-11-17 09:59:54 +01:00
|
|
|
if (!e)
|
|
|
|
{
|
|
|
|
u.i <<= 9;
|
2020-11-27 14:17:01 +01:00
|
|
|
if (u.i == 0) return FP_ILOGB0;
|
2020-11-17 09:59:54 +01:00
|
|
|
/* subnormal x */
|
|
|
|
for (e = -0x7f; u.i >> 31 == 0; e--, u.i <<= 1);
|
|
|
|
return e;
|
|
|
|
}
|
2020-11-27 14:17:01 +01:00
|
|
|
if (e == 0xff) return u.i << 9 ? FP_ILOGBNAN : INT_MAX;
|
2020-11-17 09:59:54 +01:00
|
|
|
return e - 0x7f;
|
2019-02-28 21:08:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 09:59:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ilogbl (MSVCR120.@)
|
|
|
|
*/
|
2019-02-28 21:08:13 +01:00
|
|
|
int CDECL MSVCR120_ilogbl(LDOUBLE x)
|
|
|
|
{
|
|
|
|
return MSVCR120_ilogb(x);
|
|
|
|
}
|
|
|
|
|
2017-12-22 18:38:56 +01:00
|
|
|
#endif /* _MSVCR_VER>=120 */
|