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 #pragma once
3 #ifndef _XTGMATH
4 #define _XTGMATH
5 #ifndef RC_INVOKED
6 
7  #if defined(__cplusplus)
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 _CRTIMP
39 
40 #define _GENERIC_MATH1(FUN, CRTTYPE) \
41 extern "C" 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" 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" CRTTYPE double CALL_OPT FUN(_In_ double, _In_ double); \
60 template<class _Ty1, \
61  class _Ty2> inline \
62  typename _STD enable_if< _STD _Is_numeric<_Ty1>::value \
63  && _STD _Is_numeric<_Ty2>::value, \
64  typename _STD _Common_float_type<_Ty1, _Ty2>::type>::type \
65  FUN(_Ty1 _Left, _Ty2 _Right) \
66  { \
67  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type; \
68  return (_CSTD FUN((type)_Left, (type)_Right)); \
69  }
70 
71 #define _GENERIC_MATH2(FUN, CRTTYPE) \
72  _GENERIC_MATH2_CALL(FUN, CRTTYPE, __cdecl)
73 
75 extern "C" double __cdecl pow(_In_ double, _In_ double);
76 float __CRTDECL pow(_In_ float, _In_ float) _NOEXCEPT;
77 long double __CRTDECL pow(_In_ long double, _In_ long double) _NOEXCEPT;
78 
79 template<class _Ty1,
80  class _Ty2> inline
83  typename _STD _Common_float_type<_Ty1, _Ty2>::type>::type
84  pow(const _Ty1 _Left, const _Ty2 _Right)
85  { // bring mixed types to a common type
86  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type;
87  return (_CSTD pow(type(_Left), type(_Right)));
88  }
89 
90 //_GENERIC_MATH1(abs, _CRTDEFAULT) // has integer overloads
91 _GENERIC_MATH1(acos, _CRTDEFAULT)
92 _GENERIC_MATH1(asin, _CRTDEFAULT)
93 _GENERIC_MATH1(atan, _CRTDEFAULT)
94 _GENERIC_MATH2(atan2, _CRTDEFAULT)
95 _GENERIC_MATH1(ceil, _CRTSPECIAL)
96 _GENERIC_MATH1(cos, _CRTDEFAULT)
97 _GENERIC_MATH1(cosh, _CRTDEFAULT)
98 _GENERIC_MATH1(exp, _CRTDEFAULT)
99 //_GENERIC_MATH1(fabs, _CRT_JIT_INTRINSIC) // not required
100 _GENERIC_MATH1(floor, _CRTSPECIAL)
101 _GENERIC_MATH2(fmod, _CRTDEFAULT)
102 _GENERIC_MATH1X(frexp, _Out_ int *, _CRTSPECIAL)
103 _GENERIC_MATH1X(ldexp, _In_ int, _CRTSPECIAL)
104 _GENERIC_MATH1(log, _CRTDEFAULT)
105 _GENERIC_MATH1(log10, _CRTDEFAULT)
106 //_GENERIC_MATH1(modf, _CRTDEFAULT) // types must match
107 //_GENERIC_MATH2(pow, _CRTDEFAULT) // hand crafted
108 _GENERIC_MATH1(sin, _CRTDEFAULT)
109 _GENERIC_MATH1(sinh, _CRTDEFAULT)
110 _GENERIC_MATH1(sqrt, _CRTDEFAULT)
111 _GENERIC_MATH1(tan, _CRTDEFAULT)
112 _GENERIC_MATH1(tanh, _CRTDEFAULT)
113  // C99 MATH FUNCTIONS
114 #define _GENERIC_MATH1R(FUN, RET, CRTTYPE) \
115 extern "C" 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 inline float _Fma(float _Left, float _Middle, float _Right)
125  {
126  return (_CSTD fmaf(_Left, _Middle, _Right));
127  }
128 
129 inline double _Fma(double _Left, double _Middle, double _Right)
130  {
131  return (_CSTD fma(_Left, _Middle, _Right));
132  }
133 
134 inline long double _Fma(long double _Left, long double _Middle, long double _Right)
135  {
136  return (_CSTD fmal(_Left, _Middle, _Right));
137  }
138 
139 template<class _Ty1,
140  class _Ty2,
141  class _Ty3> inline
142  typename _STD _Common_float_type<_Ty1,
143  typename _STD _Common_float_type<_Ty2, _Ty3>::type>::type
144  fma(_Ty1 _Left, _Ty2 _Middle, _Ty3 _Right)
145  { // bring mixed types to a common type
146  typedef typename _STD _Common_float_type<_Ty1,
147  typename _STD _Common_float_type<_Ty2, _Ty3>::type>::type type;
148  return (_Fma((type)_Left, (type)_Middle, (type)_Right));
149  }
150 
151  // TEMPLATE FUNCTION remquo
152 inline float _Remquo(float _Left, float _Right, int *_Pquo)
153  {
154  return (_CSTD remquof(_Left, _Right, _Pquo));
155  }
156 
157 inline double _Remquo(double _Left, double _Right, int *_Pquo)
158  {
159  return (_CSTD remquo(_Left, _Right, _Pquo));
160  }
161 
162 inline long double _Remquo(long double _Left, long double _Right, int *_Pquo)
163  {
164  return (_CSTD remquol(_Left, _Right, _Pquo));
165  }
166 
167 template<class _Ty1,
168  class _Ty2> inline
169  typename _STD _Common_float_type<_Ty1, _Ty2>::type
170  remquo(_Ty1 _Left, _Ty2 _Right, int *_Pquo)
171  { // bring mixed types to a common type
172  typedef typename _STD _Common_float_type<_Ty1, _Ty2>::type type;
173  return (_Remquo((type)_Left, (type)_Right, _Pquo));
174  }
175 
176 _GENERIC_MATH1(acosh, _CRTSPECIAL)
177 _GENERIC_MATH1(asinh, _CRTSPECIAL)
178 _GENERIC_MATH1(atanh, _CRTSPECIAL)
179 _GENERIC_MATH1(cbrt, _CRTSPECIAL)
180 _GENERIC_MATH2(copysign, _CRTSPECIAL)
181 _GENERIC_MATH1(erf, _CRTSPECIAL)
182 _GENERIC_MATH1(erfc, _CRTSPECIAL)
183 _GENERIC_MATH1(expm1, _CRTSPECIAL)
184 _GENERIC_MATH1(exp2, _CRTSPECIAL)
185 //_GENERIC_MATH1(fabs, _CRT_JIT_INTRINSIC) // not required
186 _GENERIC_MATH2(fdim, _CRTSPECIAL)
187 //_GENERIC_MATH3(fma, _CRTSPECIAL) // hand crafted
188 _GENERIC_MATH2(fmax, _CRTSPECIAL)
189 _GENERIC_MATH2(fmin, _CRTSPECIAL)
190 _GENERIC_MATH2_CALL(hypot, _CRTDEFAULT, __CRTDECL)
191 _GENERIC_MATH1R(ilogb, int, _CRTSPECIAL)
192 _GENERIC_MATH1(lgamma, _CRTSPECIAL)
193 _GENERIC_MATH1R(llrint, long long, _CRTSPECIAL)
194 _GENERIC_MATH1R(llround, long long, _CRTSPECIAL)
195 _GENERIC_MATH1(log1p, _CRTSPECIAL)
196 _GENERIC_MATH1(log2, _CRTSPECIAL)
197 _GENERIC_MATH1(logb, _CRTSPECIAL)
198 _GENERIC_MATH1R(lrint, long, _CRTSPECIAL)
199 _GENERIC_MATH1R(lround, long, _CRTSPECIAL)
200 _GENERIC_MATH1(nearbyint, _CRTSPECIAL)
201 _GENERIC_MATH2(nextafter, _CRTSPECIAL)
202 _GENERIC_MATH1X(nexttoward, _In_ long double, _CRTSPECIAL)
203 _GENERIC_MATH2(remainder, _CRTSPECIAL)
204 //_GENERIC_MATH2X(remquo, _CRTSPECIAL) // hand crafted
205 _GENERIC_MATH1(rint, _CRTSPECIAL)
206 _GENERIC_MATH1(round, _CRTSPECIAL)
207 _GENERIC_MATH1X(scalbln, _In_ long, _CRTSPECIAL)
208 _GENERIC_MATH1X(scalbn, _In_ int, _CRTSPECIAL)
209 _GENERIC_MATH1(tgamma, _CRTSPECIAL)
210 _GENERIC_MATH1(trunc, _CRTSPECIAL)
212  #endif /* defined(__cplusplus) */
213 
214  #pragma pop_macro("new")
215  #pragma warning(pop)
216  #pragma pack(pop)
217 #endif /* RC_INVOKED */
218 #endif /* _XTGMATH */
219 
220 /*
221  * Copyright (c) 1992-2013 by P.J. Plauger. ALL RIGHTS RESERVED.
222  * Consult your license regarding permissions and restrictions.
223 V6.40:0009 */
#define _Out_
Definition: sal.h:351
#define _C_STD_BEGIN
Definition: yvals.h:557
float atan(float _X) __GPU_ONLY
Calculates the arctangent of the argument
Definition: amp_math.h:325
_CRTIMP double __cdecl fdim(_In_ double _X, _In_ double _Y)
_CRTIMP double __cdecl scalbn(_In_ double _X, _In_ int _Y)
_CRTIMP float __cdecl fmaf(_In_ float _X, _In_ float _Y, _In_ float _Z)
_CRTIMP double __cdecl copysign(_In_ double _X, _In_ double _Y)
_CRTIMP double __cdecl logb(_In_ double _X)
Definition: xtr1common:80
double __cdecl fmod(_In_ double _X, _In_ double _Y)
#define _STD_BEGIN
Definition: yvals.h:553
_CRTIMP long __cdecl lrint(_In_ double _X)
float sqrt(float _X) __GPU_ONLY
Calculates the squre root of the argument
Definition: amp_math.h:1100
_CRTIMP double __cdecl lgamma(_In_ double _X)
float atan2(float _Y, float _X) __GPU_ONLY
Calculates the arctangent of _Y/_X
Definition: amp_math.h:359
_CRTIMP double __cdecl log1p(_In_ double _X)
_CRTIMP double __cdecl fmax(_In_ double _X, _In_ double _Y)
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
_CRTIMP double __cdecl ldexp(_In_ double _X, _In_ int _Y)
float exp(float _X) __GPU_ONLY
Calculates the base-e exponential of the argument
Definition: amp_math.h:471
_CRTIMP long double __cdecl fmal(_In_ long double _X, _In_ long double _Y, _In_ long double _Z)
#define _NOEXCEPT
Definition: yvals.h:25
_CRTIMP long long __cdecl llrint(_In_ double _X)
_CRTIMP double __cdecl erf(_In_ double _X)
float tanh(float _X) __GPU_ONLY
Calculates the hyperbolic tangent value of the argument
Definition: amp_math.h:1155
_CRTIMP double __cdecl floor(_In_ double _X)
_CRTIMP double __cdecl round(_In_ double _X)
_CRTIMP double __cdecl atanh(_In_ double _X)
_CRTIMP long __cdecl lround(_In_ double _X)
float sinh(float _X) __GPU_ONLY
Calculates the hyperbolic sine value of the argument
Definition: amp_math.h:1072
float log(float _X) __GPU_ONLY
Calculates the base-e logarithm of the argument
Definition: amp_math.h:774
#define _C_STD_END
Definition: yvals.h:558
_CRTIMP double __cdecl fmin(_In_ double _X, _In_ double _Y)
_CRTIMP double __cdecl log2(_In_ double _X)
#define _In_
Definition: sal.h:314
float acos(float _X) __GPU_ONLY
Calculates the arccosine of the argument
Definition: amp_math.h:269
Definition: xtr1common:66
_CRTIMP double __cdecl scalbln(_In_ double _X, _In_ long _Y)
_CRTIMP double __cdecl cbrt(_In_ double _X)
float asin(float _X) __GPU_ONLY
Calculates the arcsine of the argument
Definition: amp_math.h:297
_CRTIMP double __cdecl remainder(_In_ double _X, _In_ double _Y)
_CRTIMP double __cdecl erfc(_In_ double _X)
_CRTIMP double __cdecl frexp(_In_ double _X, _Out_ int *_Y)
float log10(float _X) __GPU_ONLY
Calculates the base-10 logarithm of the argument
Definition: amp_math.h:802
_CRTIMP double __cdecl asinh(_In_ double _X)
_CRTIMP double __cdecl nexttoward(_In_ double _X, _In_ long double _Y)
_CRTIMP double __cdecl rint(_In_ double _X)
#define __CRTDECL
Definition: crtdefs.h:622
float cos(float _X) __GPU_ONLY
Calculates the cosine of the argument
Definition: amp_math.h:415
#define _STD_END
Definition: yvals.h:554
_CRTIMP double __cdecl fma(_In_ double _X, _In_ double _Y, _In_ double _Z)
_CRTIMP double __cdecl remquo(_In_ double _X, _In_ double _Y, _Out_ int *_Z)
_CRTIMP double __cdecl exp2(_In_ double _X)
_CRTIMP double __cdecl nextafter(_In_ double _X, _In_ double _Y)
_CRTIMP double __cdecl ceil(_In_ double _X)
_CRTIMP double __cdecl acosh(_In_ double _X)
__inline double __CRTDECL hypot(_In_ double _X, _In_ double _Y)
Definition: math.h:555
Definition: xtr1common:94
#define _CSTD
Definition: yvals.h:559
_CRTIMP long double __cdecl remquol(_In_ long double _X, _In_ long double _Y, _Out_ int *_Z)
_CRTIMP long long __cdecl llround(_In_ double _X)
_CRTIMP double __cdecl expm1(_In_ double _X)
float tan(float _X) __GPU_ONLY
Calculates the tangent value of the argument
Definition: amp_math.h:1128
_CRTIMP float __cdecl remquof(_In_ float _X, _In_ float _Y, _Out_ int *_Z)
float pow(float _X, float _Y) __GPU_ONLY
Calculates _X raised to the power of _Y
Definition: amp_math.h:898
_CRTIMP double __cdecl nearbyint(_In_ double _X)
const _Ty & _Right
Definition: algorithm:4087
_CRTIMP double __cdecl tgamma(_In_ double _X)
Definition: xtr1common:306
_CRTIMP double __cdecl trunc(_In_ double _X)
_CRTIMP int __cdecl ilogb(_In_ double _X)