source: libcfa/src/math.hfa @ 343d10e

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 343d10e was e3fea42, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

change "const char *" to "const char []"

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