1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // math -- |
---|
8 | // |
---|
9 | // Author : Peter A. Buhr |
---|
10 | // Created On : Mon Apr 18 23:37:04 2016 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Fri Jul 21 17:03:13 2017 |
---|
13 | // Update Count : 101 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <math.h> |
---|
19 | #include <complex.h> |
---|
20 | |
---|
21 | static inline float ?%?( float x, float y ) { return fmodf( x, y ); } |
---|
22 | static inline float fmod( float x, float y ) { return fmodf( x, y ); } |
---|
23 | static inline double ?%?( double x, double y ) { return fmod( x, y ); } |
---|
24 | // extern "C" { double fmod( double, double ); } |
---|
25 | static inline long double ?%?( long double x, long double y ) { return fmodl( x, y ); } |
---|
26 | static inline long double fmod( long double x, long double y ) { return fmodl( x, y ); } |
---|
27 | |
---|
28 | static inline float remainder( float x, float y ) { return remainderf( x, y ); } |
---|
29 | // extern "C" { double remainder( double, double ); } |
---|
30 | static inline long double remainder( long double x, long double y ) { return remainderl( x, y ); } |
---|
31 | |
---|
32 | static inline float remquo( float x, float y, int * quo ) { return remquof( x, y, quo ); } |
---|
33 | // extern "C" { double remquo( double x, double y, int * quo ); } |
---|
34 | static inline long double remquo( long double x, long double y, int * quo ) { return remquol( x, y, quo ); } |
---|
35 | static inline [ int, float ] remquo( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; } |
---|
36 | static inline [ int, double ] remquo( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; } |
---|
37 | static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } |
---|
38 | |
---|
39 | // alternative name for remquo |
---|
40 | static inline float div( float x, float y, int * quo ) { return remquof( x, y, quo ); } |
---|
41 | static inline double div( double x, double y, int * quo ) { return remquo( x, y, quo ); } |
---|
42 | static inline long double div( long double x, long double y, int * quo ) { return remquol( x, y, quo ); } |
---|
43 | static inline [ int, float ] div( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; } |
---|
44 | static inline [ int, double ] div( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; } |
---|
45 | static inline [ int, long double ] div( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } |
---|
46 | |
---|
47 | static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); } |
---|
48 | // extern "C" { double fma( double, double, double ); } |
---|
49 | static inline long double fma( long double x, long double y, long double z ) { return fmal( x, y, z ); } |
---|
50 | |
---|
51 | static inline float fdim( float x, float y ) { return fdimf( x, y ); } |
---|
52 | // extern "C" { double fdim( double, double ); } |
---|
53 | static inline long double fdim( long double x, long double y ) { return fdiml( x, y ); } |
---|
54 | |
---|
55 | static inline float nan( const char * tag ) { return nanf( tag ); } |
---|
56 | // extern "C" { double nan( const char * ); } |
---|
57 | static inline long double nan( const char * tag ) { return nanl( tag ); } |
---|
58 | |
---|
59 | //---------------------- Exponential ---------------------- |
---|
60 | |
---|
61 | static inline float exp( float x ) { return expf( x ); } |
---|
62 | // extern "C" { double exp( double ); } |
---|
63 | static inline long double exp( long double x ) { return expl( x ); } |
---|
64 | static inline float _Complex exp( float _Complex x ) { return cexpf( x ); } |
---|
65 | static inline double _Complex exp( double _Complex x ) { return cexp( x ); } |
---|
66 | static inline long double _Complex exp( long double _Complex x ) { return cexpl( x ); } |
---|
67 | |
---|
68 | static inline float exp2( float x ) { return exp2f( x ); } |
---|
69 | // extern "C" { double exp2( double ); } |
---|
70 | static inline long double exp2( long double x ) { return exp2l( x ); } |
---|
71 | //static inline float _Complex exp2( float _Complex x ) { return cexp2f( x ); } |
---|
72 | //static inline double _Complex exp2( double _Complex x ) { return cexp2( x ); } |
---|
73 | //static inline long double _Complex exp2( long double _Complex x ) { return cexp2l( x ); } |
---|
74 | |
---|
75 | static inline float expm1( float x ) { return expm1f( x ); } |
---|
76 | // extern "C" { double expm1( double ); } |
---|
77 | static inline long double expm1( long double x ) { return expm1l( x ); } |
---|
78 | |
---|
79 | static inline float pow( float x, float y ) { return powf( x, y ); } |
---|
80 | // extern "C" { double pow( double, double ); } |
---|
81 | static inline long double pow( long double x, long double y ) { return powl( x, y ); } |
---|
82 | static inline float _Complex pow( float _Complex x, float _Complex y ) { return cpowf( x, y ); } |
---|
83 | static inline double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); } |
---|
84 | static inline long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); } |
---|
85 | |
---|
86 | //---------------------- Logarithm ---------------------- |
---|
87 | |
---|
88 | static inline float log( float x ) { return logf( x ); } |
---|
89 | // extern "C" { double log( double ); } |
---|
90 | static inline long double log( long double x ) { return logl( x ); } |
---|
91 | static inline float _Complex log( float _Complex x ) { return clogf( x ); } |
---|
92 | static inline double _Complex log( double _Complex x ) { return clog( x ); } |
---|
93 | static inline long double _Complex log( long double _Complex x ) { return clogl( x ); } |
---|
94 | |
---|
95 | static inline float log2( float x ) { return log2f( x ); } |
---|
96 | // extern "C" { double log2( double ); } |
---|
97 | static inline long double log2( long double x ) { return log2l( x ); } |
---|
98 | // static inline float _Complex log2( float _Complex x ) { return clog2f( x ); } |
---|
99 | // static inline double _Complex log2( double _Complex x ) { return clog2( x ); } |
---|
100 | // static inline long double _Complex log2( long double _Complex x ) { return clog2l( x ); } |
---|
101 | |
---|
102 | static inline float log10( float x ) { return log10f( x ); } |
---|
103 | // extern "C" { double log10( double ); } |
---|
104 | static inline long double log10( long double x ) { return log10l( x ); } |
---|
105 | // static inline float _Complex log10( float _Complex x ) { return clog10f( x ); } |
---|
106 | // static inline double _Complex log10( double _Complex x ) { return clog10( x ); } |
---|
107 | // static inline long double _Complex log10( long double _Complex x ) { return clog10l( x ); } |
---|
108 | |
---|
109 | static inline float log1p( float x ) { return log1pf( x ); } |
---|
110 | // extern "C" { double log1p( double ); } |
---|
111 | static inline long double log1p( long double x ) { return log1pl( x ); } |
---|
112 | |
---|
113 | static inline int ilogb( float x ) { return ilogbf( x ); } |
---|
114 | // extern "C" { int ilogb( double ); } |
---|
115 | static inline int ilogb( long double x ) { return ilogbl( x ); } |
---|
116 | |
---|
117 | static inline float logb( float x ) { return logbf( x ); } |
---|
118 | // extern "C" { double logb( double ); } |
---|
119 | static inline long double logb( long double x ) { return logbl( x ); } |
---|
120 | |
---|
121 | static inline float sqrt( float x ) { return sqrtf( x ); } |
---|
122 | // extern "C" { double sqrt( double ); } |
---|
123 | static inline long double sqrt( long double x ) { return sqrtl( x ); } |
---|
124 | static inline float _Complex sqrt( float _Complex x ) { return csqrtf( x ); } |
---|
125 | static inline double _Complex sqrt( double _Complex x ) { return csqrt( x ); } |
---|
126 | static inline long double _Complex sqrt( long double _Complex x ) { return csqrtl( x ); } |
---|
127 | |
---|
128 | static inline float cbrt( float x ) { return cbrtf( x ); } |
---|
129 | // extern "C" { double cbrt( double ); } |
---|
130 | static inline long double cbrt( long double x ) { return cbrtl( x ); } |
---|
131 | |
---|
132 | static inline float hypot( float x, float y ) { return hypotf( x, y ); } |
---|
133 | // extern "C" { double hypot( double, double ); } |
---|
134 | static inline long double hypot( long double x, long double y ) { return hypotl( x, y ); } |
---|
135 | |
---|
136 | //---------------------- Trigonometric ---------------------- |
---|
137 | |
---|
138 | static inline float sin( float x ) { return sinf( x ); } |
---|
139 | // extern "C" { double sin( double ); } |
---|
140 | static inline long double sin( long double x ) { return sinl( x ); } |
---|
141 | static inline float _Complex sin( float _Complex x ) { return csinf( x ); } |
---|
142 | static inline double _Complex sin( double _Complex x ) { return csin( x ); } |
---|
143 | static inline long double _Complex sin( long double _Complex x ) { return csinl( x ); } |
---|
144 | |
---|
145 | static inline float cos( float x ) { return cosf( x ); } |
---|
146 | // extern "C" { double cos( double ); } |
---|
147 | static inline long double cos( long double x ) { return cosl( x ); } |
---|
148 | static inline float _Complex cos( float _Complex x ) { return ccosf( x ); } |
---|
149 | static inline double _Complex cos( double _Complex x ) { return ccos( x ); } |
---|
150 | static inline long double _Complex cos( long double _Complex x ) { return ccosl( x ); } |
---|
151 | |
---|
152 | static inline float tan( float x ) { return tanf( x ); } |
---|
153 | // extern "C" { double tan( double ); } |
---|
154 | static inline long double tan( long double x ) { return tanl( x ); } |
---|
155 | static inline float _Complex tan( float _Complex x ) { return ctanf( x ); } |
---|
156 | static inline double _Complex tan( double _Complex x ) { return ctan( x ); } |
---|
157 | static inline long double _Complex tan( long double _Complex x ) { return ctanl( x ); } |
---|
158 | |
---|
159 | static inline float asin( float x ) { return asinf( x ); } |
---|
160 | // extern "C" { double asin( double ); } |
---|
161 | static inline long double asin( long double x ) { return asinl( x ); } |
---|
162 | static inline float _Complex asin( float _Complex x ) { return casinf( x ); } |
---|
163 | static inline double _Complex asin( double _Complex x ) { return casin( x ); } |
---|
164 | static inline long double _Complex asin( long double _Complex x ) { return casinl( x ); } |
---|
165 | |
---|
166 | static inline float acos( float x ) { return acosf( x ); } |
---|
167 | // extern "C" { double acos( double ); } |
---|
168 | static inline long double acos( long double x ) { return acosl( x ); } |
---|
169 | static inline float _Complex acos( float _Complex x ) { return cacosf( x ); } |
---|
170 | static inline double _Complex acos( double _Complex x ) { return cacos( x ); } |
---|
171 | static inline long double _Complex acos( long double _Complex x ) { return cacosl( x ); } |
---|
172 | |
---|
173 | static inline float atan( float x ) { return atanf( x ); } |
---|
174 | // extern "C" { double atan( double ); } |
---|
175 | static inline long double atan( long double x ) { return atanl( x ); } |
---|
176 | static inline float _Complex atan( float _Complex x ) { return catanf( x ); } |
---|
177 | static inline double _Complex atan( double _Complex x ) { return catan( x ); } |
---|
178 | static inline long double _Complex atan( long double _Complex x ) { return catanl( x ); } |
---|
179 | |
---|
180 | static inline float atan2( float x, float y ) { return atan2f( x, y ); } |
---|
181 | // extern "C" { double atan2( double, double ); } |
---|
182 | static inline long double atan2( long double x, long double y ) { return atan2l( x, y ); } |
---|
183 | |
---|
184 | // alternative name for atan2 |
---|
185 | static inline float atan( float x, float y ) { return atan2f( x, y ); } |
---|
186 | static inline double atan( double x, double y ) { return atan2( x, y ); } |
---|
187 | static inline long double atan( long double x, long double y ) { return atan2l( x, y ); } |
---|
188 | |
---|
189 | //---------------------- Hyperbolic ---------------------- |
---|
190 | |
---|
191 | static inline float sinh( float x ) { return sinhf( x ); } |
---|
192 | // extern "C" { double sinh( double ); } |
---|
193 | static inline long double sinh( long double x ) { return sinhl( x ); } |
---|
194 | static inline float _Complex sinh( float _Complex x ) { return csinhf( x ); } |
---|
195 | static inline double _Complex sinh( double _Complex x ) { return csinh( x ); } |
---|
196 | static inline long double _Complex sinh( long double _Complex x ) { return csinhl( x ); } |
---|
197 | |
---|
198 | static inline float cosh( float x ) { return coshf( x ); } |
---|
199 | // extern "C" { double cosh( double ); } |
---|
200 | static inline long double cosh( long double x ) { return coshl( x ); } |
---|
201 | static inline float _Complex cosh( float _Complex x ) { return ccoshf( x ); } |
---|
202 | static inline double _Complex cosh( double _Complex x ) { return ccosh( x ); } |
---|
203 | static inline long double _Complex cosh( long double _Complex x ) { return ccoshl( x ); } |
---|
204 | |
---|
205 | static inline float tanh( float x ) { return tanhf( x ); } |
---|
206 | // extern "C" { double tanh( double ); } |
---|
207 | static inline long double tanh( long double x ) { return tanhl( x ); } |
---|
208 | static inline float _Complex tanh( float _Complex x ) { return ctanhf( x ); } |
---|
209 | static inline double _Complex tanh( double _Complex x ) { return ctanh( x ); } |
---|
210 | static inline long double _Complex tanh( long double _Complex x ) { return ctanhl( x ); } |
---|
211 | |
---|
212 | static inline float asinh( float x ) { return asinhf( x ); } |
---|
213 | // extern "C" { double asinh( double ); } |
---|
214 | static inline long double asinh( long double x ) { return asinhl( x ); } |
---|
215 | static inline float _Complex asinh( float _Complex x ) { return casinhf( x ); } |
---|
216 | static inline double _Complex asinh( double _Complex x ) { return casinh( x ); } |
---|
217 | static inline long double _Complex asinh( long double _Complex x ) { return casinhl( x ); } |
---|
218 | |
---|
219 | static inline float acosh( float x ) { return acoshf( x ); } |
---|
220 | // extern "C" { double acosh( double ); } |
---|
221 | static inline long double acosh( long double x ) { return acoshl( x ); } |
---|
222 | static inline float _Complex acosh( float _Complex x ) { return cacoshf( x ); } |
---|
223 | static inline double _Complex acosh( double _Complex x ) { return cacosh( x ); } |
---|
224 | static inline long double _Complex acosh( long double _Complex x ) { return cacoshl( x ); } |
---|
225 | |
---|
226 | static inline float atanh( float x ) { return atanhf( x ); } |
---|
227 | // extern "C" { double atanh( double ); } |
---|
228 | static inline long double atanh( long double x ) { return atanhl( x ); } |
---|
229 | static inline float _Complex atanh( float _Complex x ) { return catanhf( x ); } |
---|
230 | static inline double _Complex atanh( double _Complex x ) { return catanh( x ); } |
---|
231 | static inline long double _Complex atanh( long double _Complex x ) { return catanhl( x ); } |
---|
232 | |
---|
233 | //---------------------- Error / Gamma ---------------------- |
---|
234 | |
---|
235 | static inline float erf( float x ) { return erff( x ); } |
---|
236 | // extern "C" { double erf( double ); } |
---|
237 | static inline long double erf( long double x ) { return erfl( x ); } |
---|
238 | // float _Complex erf( float _Complex ); |
---|
239 | // double _Complex erf( double _Complex ); |
---|
240 | // long double _Complex erf( long double _Complex ); |
---|
241 | |
---|
242 | static inline float erfc( float x ) { return erfcf( x ); } |
---|
243 | // extern "C" { double erfc( double ); } |
---|
244 | static inline long double erfc( long double x ) { return erfcl( x ); } |
---|
245 | // float _Complex erfc( float _Complex ); |
---|
246 | // double _Complex erfc( double _Complex ); |
---|
247 | // long double _Complex erfc( long double _Complex ); |
---|
248 | |
---|
249 | static inline float lgamma( float x ) { return lgammaf( x ); } |
---|
250 | // extern "C" { double lgamma( double ); } |
---|
251 | static inline long double lgamma( long double x ) { return lgammal( x ); } |
---|
252 | static inline float lgamma( float x, int * sign ) { return lgammaf_r( x, sign ); } |
---|
253 | static inline double lgamma( double x, int * sign ) { return lgamma_r( x, sign ); } |
---|
254 | static inline long double lgamma( long double x, int * sign ) { return lgammal_r( x, sign ); } |
---|
255 | |
---|
256 | static inline float tgamma( float x ) { return tgammaf( x ); } |
---|
257 | // extern "C" { double tgamma( double ); } |
---|
258 | static inline long double tgamma( long double x ) { return tgammal( x ); } |
---|
259 | |
---|
260 | //---------------------- Nearest Integer ---------------------- |
---|
261 | |
---|
262 | static inline float floor( float x ) { return floorf( x ); } |
---|
263 | // extern "C" { double floor( double ); } |
---|
264 | static inline long double floor( long double x ) { return floorl( x ); } |
---|
265 | |
---|
266 | static inline float ceil( float x ) { return ceilf( x ); } |
---|
267 | // extern "C" { double ceil( double ); } |
---|
268 | static inline long double ceil( long double x ) { return ceill( x ); } |
---|
269 | |
---|
270 | static inline float trunc( float x ) { return truncf( x ); } |
---|
271 | // extern "C" { double trunc( double ); } |
---|
272 | static inline long double trunc( long double x ) { return truncl( x ); } |
---|
273 | |
---|
274 | static inline float rint( float x ) { return rintf( x ); } |
---|
275 | // extern "C" { double rint( double x ); } |
---|
276 | static inline long double rint( long double x ) { return rintl( x ); } |
---|
277 | static inline long int rint( float x ) { return lrintf( x ); } |
---|
278 | static inline long int rint( double x ) { return lrint( x ); } |
---|
279 | static inline long int rint( long double x ) { return lrintl( x ); } |
---|
280 | static inline long long int rint( float x ) { return llrintf( x ); } |
---|
281 | static inline long long int rint( double x ) { return llrint( x ); } |
---|
282 | static inline long long int rint( long double x ) { return llrintl( x ); } |
---|
283 | |
---|
284 | static inline long int lrint( float x ) { return lrintf( x ); } |
---|
285 | // extern "C" { long int lrint( double ); } |
---|
286 | static inline long int lrint( long double x ) { return lrintl( x ); } |
---|
287 | static inline long long int llrint( float x ) { return llrintf( x ); } |
---|
288 | // extern "C" { long long int llrint( double ); } |
---|
289 | static inline long long int llrint( long double x ) { return llrintl( x ); } |
---|
290 | |
---|
291 | static inline float nearbyint( float x ) { return nearbyintf( x ); } |
---|
292 | // extern "C" { double nearbyint( double ); } |
---|
293 | static inline long double nearbyint( long double x ) { return nearbyintl( x ); } |
---|
294 | |
---|
295 | static inline float round( float x ) { return roundf( x ); } |
---|
296 | // extern "C" { double round( double x ); } |
---|
297 | static inline long double round( long double x ) { return roundl( x ); } |
---|
298 | static inline long int round( float x ) { return lroundf( x ); } |
---|
299 | static inline long int round( double x ) { return lround( x ); } |
---|
300 | static inline long int round( long double x ) { return lroundl( x ); } |
---|
301 | static inline long long int round( float x ) { return llroundf( x ); } |
---|
302 | static inline long long int round( double x ) { return llround( x ); } |
---|
303 | static inline long long int round( long double x ) { return llroundl( x ); } |
---|
304 | |
---|
305 | static inline long int lround( float x ) { return lroundf( x ); } |
---|
306 | // extern "C" { long int lround( double ); } |
---|
307 | static inline long int lround( long double x ) { return lroundl( x ); } |
---|
308 | static inline long long int llround( float x ) { return llroundf( x ); } |
---|
309 | // extern "C" { long long int llround( double ); } |
---|
310 | static inline long long int llround( long double x ) { return llroundl( x ); } |
---|
311 | |
---|
312 | //---------------------- Manipulation ---------------------- |
---|
313 | |
---|
314 | static inline float copysign( float x, float y ) { return copysignf( x, y ); } |
---|
315 | // extern "C" { double copysign( double, double ); } |
---|
316 | static inline long double copysign( long double x, long double y ) { return copysignl( x, y ); } |
---|
317 | |
---|
318 | static inline float frexp( float x, int * ip ) { return frexpf( x, ip ); } |
---|
319 | // extern "C" { double frexp( double, int * ); } |
---|
320 | static inline long double frexp( long double x, int * ip ) { return frexpl( x, ip ); } |
---|
321 | |
---|
322 | static inline float ldexp( float x, int exp2 ) { return ldexpf( x, exp2 ); } |
---|
323 | // extern "C" { double ldexp( double, int ); } |
---|
324 | static inline long double ldexp( long double x, int exp2 ) { return ldexpl( x, exp2 ); } |
---|
325 | |
---|
326 | static inline [ float, float ] modf( float x ) { float i; x = modff( x, &i ); return [ i, x ]; } |
---|
327 | static inline float modf( float x, float * i ) { return modff( x, i ); } |
---|
328 | static inline [ double, double ] modf( double x ) { double i; x = modf( x, &i ); return [ i, x ]; } |
---|
329 | // extern "C" { double modf( double, double * ); } |
---|
330 | static inline [ long double, long double ] modf( long double x ) { long double i; x = modfl( x, &i ); return [ i, x ]; } |
---|
331 | static inline long double modf( long double x, long double * i ) { return modfl( x, i ); } |
---|
332 | |
---|
333 | static inline float nextafter( float x, float y ) { return nextafterf( x, y ); } |
---|
334 | // extern "C" { double nextafter( double, double ); } |
---|
335 | static inline long double nextafter( long double x, long double y ) { return nextafterl( x, y ); } |
---|
336 | |
---|
337 | static inline float nexttoward( float x, long double y ) { return nexttowardf( x, y ); } |
---|
338 | // extern "C" { double nexttoward( double, long double ); } |
---|
339 | static inline long double nexttoward( long double x, long double y ) { return nexttowardl( x, y ); } |
---|
340 | |
---|
341 | static inline float scalbn( float x, int exp ) { return scalbnf( x, exp ); } |
---|
342 | // extern "C" { double scalbn( double, int ); } |
---|
343 | static inline long double scalbn( long double x, int exp ) { return scalbnl( x, exp ); } |
---|
344 | static inline float scalbn( float x, long int exp ) { return scalblnf( x, exp ); } |
---|
345 | static inline double scalbn( double x, long int exp ) { return scalbln( x, exp ); } |
---|
346 | static inline long double scalbn( long double x, long int exp ) { return scalblnl( x, exp ); } |
---|
347 | |
---|
348 | static inline float scalbln( float x, long int exp ) { return scalblnf( x, exp ); } |
---|
349 | // extern "C" { double scalbln( double, long int ); } |
---|
350 | static inline long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); } |
---|
351 | |
---|
352 | // Local Variables: // |
---|
353 | // mode: c // |
---|
354 | // tab-width: 4 // |
---|
355 | // End: // |
---|