File Index Symbol Index

//
// corecrt_math.h
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The majority of the C Standard Library <math.h> functionality.
//
#pragma once
#ifndef _INC_MATH // include guard for 3rd party interop
#define _INC_MATH
#include <corecrt.h>
#pragma warning(push)
#ifndef __assembler
// Definition of the _exception struct, which is passed to the matherr function
// when a floating point exception is detected:
struct
_exception
{
int
type
;
// exception type - see below
char
*
name
;
// name of function where error occurred
double
arg1
;
// first argument to function
double
arg2
;
// second argument (if any) to function
double
retval
;
// value to be returned by function
};
// Definition of the _complex struct to be used by those who use the complex
// functions and want type checking.
#ifndef _COMPLEX_DEFINED
#define _COMPLEX_DEFINED
struct
_complex
{
double
x
,
y
;
// real and imaginary parts
};
#if _CRT_INTERNAL_NONSTDC_NAMES && !defined __cplusplus
// Non-ANSI name for compatibility
#define complex _complex #endif #endif #endif // __assembler
// On x86, when not using /arch:SSE2 or greater, floating point operations
// are performed using the x87 instruction set and FLT_EVAL_METHOD is 2.
// (When /fp:fast is used, floating point operations may be consistent, so
// we use the default types.)
#if defined _M_IX86 && _M_IX86_FP < 2 && !defined _M_FP_FAST
typedef long double float_t;
typedef long double double_t; #else
typedef
float
float_t
;
typedef
double
double_t
;
#endif
// Constant definitions for the exception type passed in the _exception struct
#define _DOMAIN 1 // argument domain error
#define _SING 2 // argument singularity
#define _OVERFLOW 3 // overflow range error
#define _UNDERFLOW 4 // underflow range error
#define _TLOSS 5 // total loss of precision
#define _PLOSS 6 // partial loss of precision
// Definitions of _HUGE and HUGE_VAL - respectively the XENIX and ANSI names
// for a value returned in case of error by a number of the floating point
// math routines.
#ifndef __assembler
#ifndef _M_CEE_PURE
extern
double
const
_HUGE
;
#else
double const _HUGE = System::Double::PositiveInfinity; #endif #endif
#ifndef _HUGE_ENUF
#define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow #endif
#define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
#define HUGE_VAL ((double)INFINITY)
#define HUGE_VALF ((float)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
#define NAN ((float)(INFINITY * 0.0F))
#define _DENORM (-2)
#define _FINITE (-1)
#define _INFCODE 1
#define _NANCODE 2
#define FP_INFINITE _INFCODE
#define FP_NAN _NANCODE
#define FP_NORMAL _FINITE
#define FP_SUBNORMAL _DENORM
#define FP_ZERO 0
#define _C2 1 // 0 if not 2's complement
#define FP_ILOGB0 (-0x7fffffff - _C2)
#define FP_ILOGBNAN 0x7fffffff
#define MATH_ERRNO 1
#define MATH_ERREXCEPT 2
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
// Values for use as arguments to the _fperrraise function
#define _FE_DIVBYZERO 0x04
#define _FE_INEXACT 0x20
#define _FE_INVALID 0x01
#define _FE_OVERFLOW 0x08
#define _FE_UNDERFLOW 0x10
#define _D0_C 3 // little-endian, small long doubles
#define _D1_C 2
#define _D2_C 1
#define _D3_C 0
#define _DBIAS 0x3fe
#define _DOFF 4
#define _F0_C 1 // little-endian
#define _F1_C 0
#define _FBIAS 0x7e
#define _FOFF 7
#define _FRND 1
#define _L0_C 3 // little-endian, 64-bit long doubles
#define _L1_C 2
#define _L2_C 1
#define _L3_C 0
#define _LBIAS 0x3fe
#define _LOFF 4
// IEEE 754 double properties
#define _DFRAC ((unsigned short)((1 << _DOFF) - 1))
#define _DMASK ((unsigned short)(0x7fff & ~_DFRAC))
#define _DMAX ((unsigned short)((1 << (15 - _DOFF)) - 1))
#define _DSIGN ((unsigned short)0x8000)
// IEEE 754 float properties
#define _FFRAC ((unsigned short)((1 << _FOFF) - 1))
#define _FMASK ((unsigned short)(0x7fff & ~_FFRAC))
#define _FMAX ((unsigned short)((1 << (15 - _FOFF)) - 1))
#define _FSIGN ((unsigned short)0x8000)
// IEEE 754 long double properties
#define _LFRAC ((unsigned short)(-1))
#define _LMASK ((unsigned short)0x7fff)
#define _LMAX ((unsigned short)0x7fff)
#define _LSIGN ((unsigned short)0x8000)
#define _DHUGE_EXP (int)(_DMAX * 900L / 1000)
#define _FHUGE_EXP (int)(_FMAX * 900L / 1000)
#define _LHUGE_EXP (int)(_LMAX * 900L / 1000)
#define _DSIGN_C(_Val) (((_double_val *)(char*)&(_Val))->_Sh[_D0_C] & _DSIGN)
#define _FSIGN_C(_Val) (((_float_val *)(char*)&(_Val))->_Sh[_F0_C] & _FSIGN)
#define _LSIGN_C(_Val) (((_ldouble_val*)(char*)&(_Val))->_Sh[_L0_C] & _LSIGN)
// double declarations
typedef
union
{
// pun floating type as integer array
unsigned
short
_Sh
[
4
];
double
_Val
; }
_double_val
;
// float declarations
typedef
union
{
// pun floating type as integer array
unsigned
short
_Sh
[
2
];
float
_Val
; }
_float_val
;
// long double declarations
typedef
union
{
// pun floating type as integer array
unsigned
short
_Sh
[
4
];
long
double
_Val
; }
_ldouble_val
;
typedef
union
{
// pun float types as integer array
unsigned
short
_Word
[
4
];
float
_Float
;
double
_Double
;
long
double
_Long_double
; }
_float_const
;
extern
const
_float_const
_Denorm_C
,
_Inf_C
,
_Nan_C
,
_Snan_C
,
_Hugeval_C
;
extern
const
_float_const
_FDenorm_C
,
_FInf_C
,
_FNan_C
,
_FSnan_C
;
extern
const
_float_const
_LDenorm_C
,
_LInf_C
,
_LNan_C
,
_LSnan_C
;
extern
const
_float_const
_Eps_C
,
_Rteps_C
;
extern
const
_float_const
_FEps_C
,
_FRteps_C
;
extern
const
_float_const
_LEps_C
,
_LRteps_C
;
extern
const
double
_Zero_C
,
_Xbig_C
;
extern
const
float
_FZero_C
,
_FXbig_C
;
extern
const
long
double
_LZero_C
,
_LXbig_C
;
#define _FP_LT 1
#define _FP_EQ 2
#define _FP_GT 4
#ifndef __cplusplus
#define _CLASS_ARG(_Val) __pragma(warning(suppress:6334))(sizeof ((_Val) + (float)0) == sizeof (float) ? 'f' : sizeof ((_Val) + (double)0) == sizeof (double) ? 'd' : 'l')
#define _CLASSIFY(_Val, _FFunc, _DFunc, _LDFunc) (_CLASS_ARG(_Val) == 'f' ? _FFunc((float)(_Val)) : _CLASS_ARG(_Val) == 'd' ? _DFunc((double)(_Val)) : _LDFunc((long double)(_Val)))
#define _CLASSIFY2(_Val1, _Val2, _FFunc, _DFunc, _LDFunc) (_CLASS_ARG((_Val1) + (_Val2)) == 'f' ? _FFunc((float)(_Val1), (float)(_Val2)) : _CLASS_ARG((_Val1) + (_Val2)) == 'd' ? _DFunc((double)(_Val1), (double)(_Val2)) : _LDFunc((long double)(_Val1), (long double)(_Val2)))
#define fpclassify(_Val) (_CLASSIFY(_Val, _fdclass, _dclass, _ldclass))
#define _FPCOMPARE(_Val1, _Val2) (_CLASSIFY2(_Val1, _Val2, _fdpcomp, _dpcomp, _ldpcomp))
#define isfinite(_Val) (fpclassify(_Val) <= 0)
#define isinf(_Val) (fpclassify(_Val) == FP_INFINITE)
#define isnan(_Val) (fpclassify(_Val) == FP_NAN)
#define isnormal(_Val) (fpclassify(_Val) == FP_NORMAL)
#define signbit(_Val) (_CLASSIFY(_Val, _fdsign, _dsign, _ldsign))
#define isgreater(x, y) ((_FPCOMPARE(x, y) & _FP_GT) != 0)
#define isgreaterequal(x, y) ((_FPCOMPARE(x, y) & (_FP_EQ | _FP_GT)) != 0)
#define isless(x, y) ((_FPCOMPARE(x, y) & _FP_LT) != 0)
#define islessequal(x, y) ((_FPCOMPARE(x, y) & (_FP_LT | _FP_EQ)) != 0)
#define islessgreater(x, y) ((_FPCOMPARE(x, y) & (_FP_LT | _FP_GT)) != 0)
#define isunordered(x, y) (_FPCOMPARE(x, y) == 0)
#else // __cplusplus
extern
"C++"
{ {
return
_fdtest
(&
_X
); } {
return
_dtest
(&
_X
); } {
return
_ldtest
(&
_X
); } {
return
_fdsign
(
_X
) !=
0
; } {
return
_dsign
(
_X
) !=
0
; } {
return
_ldsign
(
_X
) !=
0
; } {
return
_fdpcomp
(
_X
,
_Y
); } {
return
_dpcomp
(
_X
,
_Y
); } {
return
_ldpcomp
(
_X
,
_Y
); }
template
<
class
_Trc
,
class
_Tre
>
struct
_Combined_type
{
// determine combined type
typedef
float
_Type
; };
template
<>
struct
_Combined_type
<
float
,
double
> {
// determine combined type
typedef
double
_Type
; };
template
<>
struct
_Combined_type
<
float
,
long
double
> {
// determine combined type
typedef
long
double
_Type
; };
template
<
class
_Ty
,
class
_T2
>
struct
_Real_widened
{
// determine widened real type
typedef
long
double
_Type
; };
template
<>
struct
_Real_widened
<
float
,
float
> {
// determine widened real type
typedef
float
_Type
; };
template
<>
struct
_Real_widened
<
float
,
double
> {
// determine widened real type
typedef
double
_Type
; };
template
<>
struct
_Real_widened
<
double
,
float
> {
// determine widened real type
typedef
double
_Type
; };
template
<>
struct
_Real_widened
<
double
,
double
> {
// determine widened real type
typedef
double
_Type
; };
template
<
class
_Ty
>
struct
_Real_type
{
// determine equivalent real type
typedef
double
_Type
;
// default is double
};
template
<>
struct
_Real_type
<
float
> {
// determine equivalent real type
typedef
float
_Type
; };
template
<>
struct
_Real_type
<
long
double
> {
// determine equivalent real type
typedef
long
double
_Type
; };
template
<
class
_T1
,
class
_T2
> {
// compare _Left and _Right
typedef
typename
_Combined_type
<
float
,
typename
_Real_widened
<
typename
_Real_type
<
_T1
>::
_Type
,
typename
_Real_type
<
_T2
>::
_Type
>::
_Type
>::
_Type
_Tw
;
return
_fpcomp
((
_Tw
)
_X
, (
_Tw
)
_Y
); }
template
<
class
_Ty
> {
return
fpclassify
(
_X
) <=
0
; }
template
<
class
_Ty
> { }
template
<
class
_Ty
> { }
template
<
class
_Ty
> { }
template
<
class
_Ty1
,
class
_Ty2
> { }
template
<
class
_Ty1
,
class
_Ty2
> { }
template
<
class
_Ty1
,
class
_Ty2
> { }
template
<
class
_Ty1
,
class
_Ty2
> { }
template
<
class
_Ty1
,
class
_Ty2
> { }
template
<
class
_Ty1
,
class
_Ty2
> {
return
_fpcomp
(
_X
,
_Y
) ==
0
; } }
// extern "C++"
#endif // __cplusplus
#if _CRT_FUNCTIONS_REQUIRED
#if defined _M_IX86
#endif
#if defined _M_X64
_Check_return_ _ACRTIMP float __cdecl _logbf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl _nextafterf(_In_ float _X, _In_ float _Y);
_Check_return_ _ACRTIMP int __cdecl _finitef(_In_ float _X);
_Check_return_ _ACRTIMP int __cdecl _isnanf(_In_ float _X);
_Check_return_ _ACRTIMP int __cdecl _fpclassf(_In_ float _X);
_Check_return_ _ACRTIMP int __cdecl _set_FMA3_enable(_In_ int _Flag);
_Check_return_ _ACRTIMP int __cdecl _get_FMA3_enable(void);
#elif defined _M_ARM || defined _M_ARM64 || defined _M_HYBRID_X86_ARM64
_Check_return_ _ACRTIMP int __cdecl _finitef(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl _logbf(_In_ float _X);
#endif
#if defined _M_X64 || defined _M_ARM || defined _M_ARM64 || defined _M_HYBRID_X86_ARM64 || defined _CORECRT_BUILD_APISET
_Check_return_ _ACRTIMP float __cdecl acosf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl asinf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl atan2f(_In_ float _Y, _In_ float _X);
_Check_return_ _ACRTIMP float __cdecl atanf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl ceilf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl cosf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl coshf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl expf(_In_ float _X);
#else
{
return
(
float
)
acos
(
_X
); } {
return
(
float
)
asin
(
_X
); } {
return
(
float
)
atan2
(
_Y
,
_X
); } {
return
(
float
)
atan
(
_X
); } {
return
(
float
)
ceil
(
_X
); } {
return
(
float
)
cos
(
_X
); } {
return
(
float
)
cosh
(
_X
); } {
return
(
float
)
exp
(
_X
); }
#endif
#if defined _M_ARM || defined _M_ARM64 || defined _M_HYBRID_X86_ARM64
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP float __cdecl fabsf(_In_ float _X);
#else
{
return
(
float
)
fabs
(
_X
); }
#endif
#if defined _M_X64 || defined _M_ARM || defined _M_ARM64 || defined _M_HYBRID_X86_ARM64
_Check_return_ _ACRTIMP float __cdecl floorf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl fmodf(_In_ float _X, _In_ float _Y);
#else
{
return
(
float
)
floor
(
_X
); } {
return
(
float
)
fmod
(
_X
,
_Y
); }
#endif
{
return
(
float
)
frexp
(
_X
,
_Y
); } {
return
_hypotf
(
_X
,
_Y
); } {
return
(
float
)
ldexp
(
_X
,
_Y
); }
#if defined _M_X64 || defined _M_ARM || defined _M_ARM64 || defined _M_HYBRID_X86_ARM64 || defined _CORECRT_BUILD_APISET
_Check_return_ _ACRTIMP float __cdecl log10f(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl logf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl modff(_In_ float _X, _Out_ float *_Y);
_Check_return_ _ACRTIMP float __cdecl powf(_In_ float _X, _In_ float _Y);
_Check_return_ _ACRTIMP float __cdecl sinf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl sinhf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl sqrtf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl tanf(_In_ float _X);
_Check_return_ _ACRTIMP float __cdecl tanhf(_In_ float _X);
#else
{
return
(
float
)
log10
(
_X
); } {
return
(
float
)
log
(
_X
); } {
double
_F
,
_I
;
_F
=
modf
(
_X
, &
_I
); *
_Y
= (
float
)
_I
;
return
(
float
)
_F
; } {
return
(
float
)
pow
(
_X
,
_Y
); } {
return
(
float
)
sin
(
_X
); } {
return
(
float
)
sinh
(
_X
); } {
return
(
float
)
sqrt
(
_X
); } {
return
(
float
)
tan
(
_X
); } {
return
(
float
)
tanh
(
_X
); }
#endif
{
return
acos
((
double
)
_X
); } {
return
asin
((
double
)
_X
); } {
return
atan2
((
double
)
_Y
, (
double
)
_X
); } {
return
atan
((
double
)
_X
); } {
return
ceil
((
double
)
_X
); } {
return
_chgsign
((
double
)
_X
); } {
return
_copysign
((
double
)
_Number
, (
double
)
_Sign
); } {
return
cosh
((
double
)
_X
); } {
return
cos
((
double
)
_X
); } {
return
exp
((
double
)
_X
); } {
return
fabs
((
double
)
_X
); } {
return
floor
((
double
)
_X
); } {
return
fmod
((
double
)
_X
, (
double
)
_Y
); } {
return
frexp
((
double
)
_X
,
_Y
); } {
return
_hypot
((
double
)
_X
, (
double
)
_Y
); } {
return
_hypot
((
double
)
_X
, (
double
)
_Y
); } {
return
ldexp
((
double
)
_X
,
_Y
); } {
return
log
((
double
)
_X
); } {
return
log10
((
double
)
_X
); } {
double
_F
,
_I
;
_F
=
modf
((
double
)
_X
, &
_I
); *
_Y
=
_I
;
return
_F
; } {
return
pow
((
double
)
_X
, (
double
)
_Y
); } {
return
sinh
((
double
)
_X
); } {
return
sin
((
double
)
_X
); } {
return
sqrt
((
double
)
_X
); } {
return
tanh
((
double
)
_X
); } {
return
tan
((
double
)
_X
); }
#ifndef __cplusplus
#define _matherrl _matherr
#endif
#endif // _CRT_FUNCTIONS_REQUIRED
#if _CRT_INTERNAL_NONSTDC_NAMES
#define DOMAIN _DOMAIN
#define SING _SING
#define OVERFLOW _OVERFLOW
#define UNDERFLOW _UNDERFLOW
#define TLOSS _TLOSS
#define PLOSS _PLOSS
#define matherr _matherr
#ifndef __assembler
#ifndef _M_CEE_PURE
extern
double
HUGE
;
#else
double const HUGE = _HUGE; #endif
#endif // _CRT_INTERNAL_NONSTDC_NAMES
#pragma warning(pop)