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