STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
xtgmath.h
Go to the documentation of this file.
1 /* xtgmath.h internal header */
2 
3  #if defined(__cplusplus)
4 #pragma once
5 #ifndef _XTGMATH
6 #define _XTGMATH
7 #ifndef RC_INVOKED
8 #include <xtr1common>
9 
10  #pragma pack(push,_CRT_PACKING)
11  #pragma warning(push,3)
12  #pragma push_macro("new")
13  #undef new
14 
16 template<class _Ty>
17  struct _Promote_to_float
18  { // promote integral to double
19  typedef typename conditional<is_integral<_Ty>::value,
20  double, _Ty>::type type;
21  };
22 
23 template<class _Ty1,
24  class _Ty2>
25  struct _Common_float_type
26  { // find type for two-argument math function
27  typedef typename _Promote_to_float<_Ty1>::type _Ty1f;
28  typedef typename _Promote_to_float<_Ty2>::type _Ty2f;
30  || is_same<_Ty2f, long double>::value, long double,
33  float>::type>::type type;
34  };
36 
37 #define _CRTDEFAULT
38 #define _CRTSPECIAL _ACRTIMP
39 
40 #define _GENERIC_MATH1(FUN, CRTTYPE) \
41 extern "C" _Check_return_ CRTTYPE double __cdecl FUN(_In_ double); \
42 template<class _Ty> inline \
43  typename _STD enable_if< _STD is_integral<_Ty>::value, double>::type \
44  FUN(_Ty _Left) \
45  { \
46  return (_CSTD FUN((double)_Left)); \
47  }
48 
49 #define _GENERIC_MATH1X(FUN, ARG2, CRTTYPE) \
50 extern "C" _Check_return_ CRTTYPE double __cdecl FUN(_In_ double, ARG2); \
51 template<class _Ty> inline \
52  typename _STD enable_if< _STD is_integral<_Ty>::value, double>::type \
53  FUN(_Ty _Left, ARG2 _Arg2) \
54  { \
55  return (_CSTD FUN((double)_Left, _Arg2)); \
56  }
57 
58 #define _GENERIC_MATH2_CALL(FUN, CRTTYPE, CALL_OPT) \
59 extern "C" _Check_return_ CRTTYPE double CALL_OPT FUN( \
60  _In_ double, _In_ double); \
61 template<class _Ty1, \
62  class _Ty2> inline \
63  typename _STD enable_if< _STD is_arithmetic<_Ty1>::value \
64  && _STD is_arithmetic<_Ty2>::value, \
65  typename _STD _Common_float_type<_Ty1, _Ty2>::type>::type \
66  FUN(_Ty1 _Left, _Ty2 _Right) \
67  { \
68  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type; \
69  return (_CSTD FUN((type)_Left, (type)_Right)); \
70  }
71 
72 #define _GENERIC_MATH2(FUN, CRTTYPE) \
73  _GENERIC_MATH2_CALL(FUN, CRTTYPE, __cdecl)
74 
76 template<class _Ty1,
77  class _Ty2> inline
80  typename _STD _Common_float_type<_Ty1, _Ty2>::type>::type
81  pow(const _Ty1 _Left, const _Ty2 _Right)
82  { // bring mixed types to a common type
83  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type;
84  return (_CSTD pow(type(_Left), type(_Right)));
85  }
86 
87 //_GENERIC_MATH1(abs, _CRTDEFAULT) // has integer overloads
88 _GENERIC_MATH1(acos, _CRTDEFAULT)
89 _GENERIC_MATH1(asin, _CRTDEFAULT)
90 _GENERIC_MATH1(atan, _CRTDEFAULT)
91 _GENERIC_MATH2(atan2, _CRTDEFAULT)
92 _GENERIC_MATH1(ceil, _CRTSPECIAL)
93 _GENERIC_MATH1(cos, _CRTDEFAULT)
94 _GENERIC_MATH1(cosh, _CRTDEFAULT)
95 _GENERIC_MATH1(exp, _CRTDEFAULT)
96 
97 _GENERIC_MATH1(fabs, _CRT_JIT_INTRINSIC)
98 
99 _GENERIC_MATH1(floor, _CRTSPECIAL)
100 _GENERIC_MATH2(fmod, _CRTDEFAULT)
101 _GENERIC_MATH1X(frexp, _Out_ int *, _CRTSPECIAL)
102 _GENERIC_MATH1X(ldexp, _In_ int, _CRTSPECIAL)
103 _GENERIC_MATH1(log, _CRTDEFAULT)
104 _GENERIC_MATH1(log10, _CRTDEFAULT)
105 //_GENERIC_MATH1(modf, _CRTDEFAULT) // types must match
106 //_GENERIC_MATH2(pow, _CRTDEFAULT) // hand crafted
107 _GENERIC_MATH1(sin, _CRTDEFAULT)
108 _GENERIC_MATH1(sinh, _CRTDEFAULT)
109 _GENERIC_MATH1(sqrt, _CRTDEFAULT)
110 _GENERIC_MATH1(tan, _CRTDEFAULT)
111 _GENERIC_MATH1(tanh, _CRTDEFAULT)
112 
113  // C99 MATH FUNCTIONS
114 #define _GENERIC_MATH1R(FUN, RET, CRTTYPE) \
115 extern "C" _Check_return_ CRTTYPE RET __cdecl FUN(_In_ double); \
116 template<class _Ty> inline \
117  typename _STD enable_if< _STD is_integral<_Ty>::value, RET>::type \
118  FUN(_Ty _Left) \
119  { \
120  return (_CSTD FUN((double)_Left)); \
121  }
122 
123  // TEMPLATE FUNCTION fma
124 
125 inline float _Fma(float _Left, float _Middle, float _Right)
126  { // call float fma
127  return (_CSTD fmaf(_Left, _Middle, _Right));
128  }
129 
130 inline double _Fma(double _Left, double _Middle, double _Right)
131  { // call double fma
132  return (_CSTD fma(_Left, _Middle, _Right));
133  }
134 
135 inline long double _Fma(long double _Left, long double _Middle,
136  long double _Right)
137  { // call long double fma
138  return (_CSTD fmal(_Left, _Middle, _Right));
139  }
140 
141 template<class _Ty1,
142  class _Ty2,
143  class _Ty3> inline
144  typename _STD _Common_float_type<_Ty1,
145  typename _STD _Common_float_type<_Ty2, _Ty3>::type>::type
146  fma(_Ty1 _Left, _Ty2 _Middle, _Ty3 _Right)
147  { // bring mixed types to a common type
148  typedef typename _STD _Common_float_type<_Ty1,
149  typename _STD _Common_float_type<_Ty2, _Ty3>::type>::type type;
150  return (_Fma((type)_Left, (type)_Middle, (type)_Right));
151  }
152 
153  // TEMPLATE FUNCTION remquo
154 
155 inline float _Remquo(float _Left, float _Right, int *_Pquo)
156  { // call float remquo
157  return (_CSTD remquof(_Left, _Right, _Pquo));
158  }
159 
160 inline double _Remquo(double _Left, double _Right, int *_Pquo)
161  { // call double remquo
162  return (_CSTD remquo(_Left, _Right, _Pquo));
163  }
164 
165 inline long double _Remquo(long double _Left, long double _Right, int *_Pquo)
166  { // call long double remquo
167  return (_CSTD remquol(_Left, _Right, _Pquo));
168  }
169 
170 template<class _Ty1,
171  class _Ty2> inline
172  typename _STD _Common_float_type<_Ty1, _Ty2>::type
173  remquo(_Ty1 _Left, _Ty2 _Right, int *_Pquo)
174  { // bring mixed types to a common type
175  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type;
176  return (_Remquo((type)_Left, (type)_Right, _Pquo));
177  }
178 
179 _GENERIC_MATH1(acosh, _CRTSPECIAL)
180 _GENERIC_MATH1(asinh, _CRTSPECIAL)
181 _GENERIC_MATH1(atanh, _CRTSPECIAL)
182 _GENERIC_MATH1(cbrt, _CRTSPECIAL)
183 _GENERIC_MATH2(copysign, _CRTSPECIAL)
184 _GENERIC_MATH1(erf, _CRTSPECIAL)
185 _GENERIC_MATH1(erfc, _CRTSPECIAL)
186 _GENERIC_MATH1(expm1, _CRTSPECIAL)
187 _GENERIC_MATH1(exp2, _CRTSPECIAL)
188 _GENERIC_MATH2(fdim, _CRTSPECIAL)
189 //_GENERIC_MATH3(fma, _CRTSPECIAL) // hand crafted
190 _GENERIC_MATH2(fmax, _CRTSPECIAL)
191 _GENERIC_MATH2(fmin, _CRTSPECIAL)
192 _GENERIC_MATH2(hypot, _CRTSPECIAL)
193 _GENERIC_MATH1R(ilogb, int, _CRTSPECIAL)
194 _GENERIC_MATH1(lgamma, _CRTSPECIAL)
195 _GENERIC_MATH1R(llrint, long long, _CRTSPECIAL)
196 _GENERIC_MATH1R(llround, long long, _CRTSPECIAL)
197 _GENERIC_MATH1(log1p, _CRTSPECIAL)
198 _GENERIC_MATH1(log2, _CRTSPECIAL)
199 _GENERIC_MATH1(logb, _CRTSPECIAL)
200 _GENERIC_MATH1R(lrint, long, _CRTSPECIAL)
201 _GENERIC_MATH1R(lround, long, _CRTSPECIAL)
202 _GENERIC_MATH1(nearbyint, _CRTSPECIAL)
203 _GENERIC_MATH2(nextafter, _CRTSPECIAL)
204 _GENERIC_MATH1X(nexttoward, _In_ long double, _CRTSPECIAL)
205 _GENERIC_MATH2(remainder, _CRTSPECIAL)
206 //_GENERIC_MATH2X(remquo, _CRTSPECIAL) // hand crafted
207 _GENERIC_MATH1(rint, _CRTSPECIAL)
208 _GENERIC_MATH1(round, _CRTSPECIAL)
209 _GENERIC_MATH1X(scalbln, _In_ long, _CRTSPECIAL)
210 _GENERIC_MATH1X(scalbn, _In_ int, _CRTSPECIAL)
211 _GENERIC_MATH1(tgamma, _CRTSPECIAL)
212 _GENERIC_MATH1(trunc, _CRTSPECIAL)
214  #pragma pop_macro("new")
215  #pragma warning(pop)
216  #pragma pack(pop)
217 #endif /* RC_INVOKED */
218 #endif /* _XTGMATH */
219  #endif /* defined(__cplusplus) */
220 
221 /*
222  * Copyright (c) by P.J. Plauger. All rights reserved.
223  * Consult your license regarding permissions and restrictions.
224 V6.50:0009 */
#define _Out_
Definition: sal.h:342
#define _C_STD_BEGIN
Definition: yvals.h:568
float atan(float _X) __GPU_ONLY
Calculates the arctangent of the argument
Definition: amp_math.h:325
float acosh(float _X) __GPU_ONLY
Calculates the inverse hyperbolic cosine of the argument
Definition: amp_math.h:1323
constexpr const _Ty &() _Left
Definition: algorithm:3590
float fmaf(float _X, float _Y, float _Z) __GPU_ONLY
Compute (_X * _Y) + _Z, rounded as one ternary operation
Definition: amp_math.h:2312
_Check_return_ long long llround(_In_ float _Xx) _NOEXCEPT
Definition: cmath:187
float atanh(float _X) __GPU_ONLY
Calculates the inverse hyperbolic tangent of the argument
Definition: amp_math.h:1544
float lgamma(float _X, _Out_ int *_Sign) __GPU_ONLY
Computes the natural logarithm of the absolute value of gamma of the argument
Definition: amp_math.h:2875
float logb(float _X) __GPU_ONLY
Extracts the exponent of _X, as a signed integer value in floating-point format
Definition: amp_math.h:3088
Definition: xtr1common:71
float fmod(float _X, float _Y) __GPU_ONLY
Calculates the floating-point remainder of _X/_Y
Definition: amp_math.h:629
#define _STD_BEGIN
Definition: yvals.h:564
float sqrt(float _X) __GPU_ONLY
Calculates the squre root of the argument
Definition: amp_math.h:1100
float atan2(float _Y, float _X) __GPU_ONLY
Calculates the arctangent of _Y/_X
Definition: amp_math.h:359
float trunc(float _X) __GPU_ONLY
Truncates the argument to the integer component
Definition: amp_math.h:1183
float fmax(float _X, float _Y) __GPU_ONLY
Determine the maximum numeric value of the arguments
Definition: amp_math.h:561
float cosh(float _X) __GPU_ONLY
Calculates the hyperbolic cosine value of the argument
Definition: amp_math.h:443
float sin(float _X) __GPU_ONLY
Calculates the sine value of the argument
Definition: amp_math.h:1010
float exp(float _X) __GPU_ONLY
Calculates the base-e exponential of the argument
Definition: amp_math.h:471
float fdim(float _X, float _Y) __GPU_ONLY
Determines the positive difference between the arguments
Definition: amp_math.h:2232
float tanh(float _X) __GPU_ONLY
Calculates the hyperbolic tangent value of the argument
Definition: amp_math.h:1155
_Check_return_ float rint(_In_ float _Xx) _NOEXCEPT
Definition: cmath:273
float hypot(float _X, float _Y) __GPU_ONLY
Computes the square root of the sum of the squares of _X and _Y
Definition: amp_math.h:2619
float remquof(float _X, float _Y, _Out_ int *_Quo) __GPU_ONLY
Computes the same remainder as _X REM _Y. Also calculates the lower 24 bits of the integral quotient ...
Definition: amp_math.h:3537
float round(float _X) __GPU_ONLY
Rounds _X to the nearest integer
Definition: amp_math.h:926
float log2(float _X) __GPU_ONLY
Calculates the base-2 logarithm of the argument
Definition: amp_math.h:830
float sinh(float _X) __GPU_ONLY
Calculates the hyperbolic sine value of the argument
Definition: amp_math.h:1072
_Check_return_ long lround(_In_ float _Xx) _NOEXCEPT
Definition: cmath:222
float tgamma(float _X) __GPU_ONLY
Computes the gamma function of _X
Definition: amp_math.h:4061
float log(float _X) __GPU_ONLY
Calculates the base-e logarithm of the argument
Definition: amp_math.h:774
float asinh(float _X) __GPU_ONLY
Calculates the inverse hyperbolic sine of the argument
Definition: amp_math.h:1408
float remainder(float _X, float _Y) __GPU_ONLY
Computes the remainder: _X REM _Y
Definition: amp_math.h:3497
Definition: xtr1common:287
#define _C_STD_END
Definition: yvals.h:569
float nearbyint(float _X) __GPU_ONLY
Rounds the argument to an integer value in floating-point format, using the current rounding directio...
Definition: amp_math.h:3212
_Check_return_ long long llrint(_In_ float _Xx) _NOEXCEPT
Definition: cmath:182
_Check_return_ long lrint(_In_ float _Xx) _NOEXCEPT
Definition: cmath:217
#define _In_
Definition: sal.h:305
float remquo(float _X, float _Y, _Out_ int *_Quo) __GPU_ONLY
Computes the same remainder as _X REM _Y. Also calculates the lower 24 bits of the integral quotient ...
Definition: amp_math.h:3560
float acos(float _X) __GPU_ONLY
Calculates the arccosine of the argument
Definition: amp_math.h:269
Definition: xtr1common:57
float asin(float _X) __GPU_ONLY
Calculates the arcsine of the argument
Definition: amp_math.h:297
float frexp(float _X, _Out_ int *_Exp) __GPU_ONLY
Gets the mantissa and exponent of _X
Definition: amp_math.h:669
float fmin(float _X, float _Y) __GPU_ONLY
Determine the minimum numeric value of the arguments
Definition: amp_math.h:595
float erfc(float _X) __GPU_ONLY
Computes the complementary error function of _X
Definition: amp_math.h:1889
float log1p(float _X) __GPU_ONLY
Calculates the base-e logarithm of 1 plus the argument
Definition: amp_math.h:3046
float log10(float _X) __GPU_ONLY
Calculates the base-10 logarithm of the argument
Definition: amp_math.h:802
float nextafter(float _X, float _Y) __GPU_ONLY
Determine the next representable value, in the type of the function, after _X in the direction of _Y ...
Definition: amp_math.h:3266
float expm1(float _X) __GPU_ONLY
Calculates the base-e exponential of the argument, minus 1
Definition: amp_math.h:2141
float cos(float _X) __GPU_ONLY
Calculates the cosine of the argument
Definition: amp_math.h:415
#define _STD_END
Definition: yvals.h:565
float ldexp(float _X, int _Exp) __GPU_ONLY
Computes a real number from the mantissa and exponent
Definition: amp_math.h:746
float floor(float _X) __GPU_ONLY
Calculates the floor of the argument
Definition: amp_math.h:527
float copysign(float _X, float _Y) __GPU_ONLY
Produces a value with the magnitude of _X and the sign of _Y
Definition: amp_math.h:1676
_Check_return_ float scalbln(_In_ float _Xx, _In_ long _Yx) _NOEXCEPT
Definition: cmath:283
Definition: xtr1common:86
#define _CSTD
Definition: yvals.h:570
int ilogb(float _X) __GPU_ONLY
Extract the exponent of _X as a signed int value
Definition: amp_math.h:2664
float tan(float _X) __GPU_ONLY
Calculates the tangent value of the argument
Definition: amp_math.h:1128
float cbrt(float _X) __GPU_ONLY
Computes the real cube root of the argument
Definition: amp_math.h:1586
float fma(float _X, float _Y, float _Z) __GPU_ONLY
Compute (_X * _Y) + _Z, rounded as one ternary operation
Definition: amp_math.h:2332
float erf(float _X) __GPU_ONLY
Computes the error function of _X
Definition: amp_math.h:1847
float pow(float _X, float _Y) __GPU_ONLY
Calculates _X raised to the power of _Y
Definition: amp_math.h:898
float scalbn(float _X, int _Y) __GPU_ONLY
Multiplies _X by FLT_RADIX to the power _Y
Definition: amp_math.h:3752
float ceil(float _X) __GPU_ONLY
Calculates the ceiling of the argument
Definition: amp_math.h:387
float exp2(float _X) __GPU_ONLY
Calculates the base-2 exponential of the argument
Definition: amp_math.h:499
constexpr const _Ty &() _Right
Definition: algorithm:3591
float fabs(float _X) __GPU_ONLY
Returns the absolute value of the argument
Definition: amp_math.h:241
_Check_return_ float nexttoward(_In_ float _Xx, _In_ long double _Yx) _NOEXCEPT
Definition: cmath:242