1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
8 // ----------------------------------------------------------------------------
11 #define __MATH_H __MATH_H
13 // ----------------------------------------------------------------------------
16 #define HUGE_VAL // TODO
17 #define HUGE_VALF // TODO
18 #define HUGE_VALL // TODO
20 #define INFINITY // TODO
23 #define FP_FAST_FMA // TODO
24 #define FP_FAST_FMAF // TODO
25 #define FP_FAST_FMAL // TODO
27 #define FP_INFINITE // TODO
28 #define FP_NAN // TODO
29 #define FP_NORMAL // TODO
30 #define FP_SUBNORMAL // TODO
31 #define FP_ZERO // TODO
33 #define FP_ILOGB0 // TODO
34 #define FP_ILOGBNAN // TODO
37 #define MATH_ERREXCEPT 2
38 #define math_errhandling // TODO
40 // --------------------------------------------------------------------------
43 typedef double_t; // TODO
44 typedef float_t; // TODO
46 // --------------------------------------------------------------------------
51 #define isgreater( x, y ) // TODO
52 #define isgreaterequal( x, y ) // TODO
53 #define isless( x, y ) // TODO
54 #define islessequal( x, y ) // TODO
55 #define islessgreater( x, y ) // TODO
56 #define isunordered( x, y ) // TODO
57 #define fpclassify( x ) // TODO
58 #define isfinite( x ) // TODO
60 #define isinf( x ) // TODO
61 #define isnan( x ) // TODO
62 #define isnormal( x ) // TODO
63 #define signbit( x ) // TODO
67 // The same functionality as above is implemented as functions in C++.
68 bool signbit( float x );
69 bool signbit( double x );
70 bool signbit( long double x );
71 int fpclassify( float x );
72 int fpclassify( double x );
73 int fpclassify( long double x );
74 bool isfinite( float x );
75 bool isfinite( double x );
76 bool isfinite( long double x );
77 bool isinf( float x );
78 bool isinf( double x );
79 bool isinf( long double x );
80 bool isnan( float x );
81 bool isnan( double x );
82 bool isnan( long double x );
83 bool isnormal( float x );
84 bool isnormal( double x );
85 bool isnormal( long double x );
86 bool isgreater( float x, float y );
87 bool isgreater( double x, double y );
88 bool isgreater( long double x, long double y );
89 bool isgreaterequal( float x, float y );
90 bool isgreaterequal( double x, double y );
91 bool isgreaterequal( long double x, long double y );
92 bool isless( float x, float y );
93 bool isless( double x, double y );
94 bool isless( long double x, long double y );
95 bool islessequal( float x, float y );
96 bool islessequal( double x, double y );
97 bool islessequal( long double x, long double y );
98 bool islessgreater( float x, float y );
99 bool islessgreater( double x, double y );
100 bool islessgreater( long double x, long double y );
101 bool isunordered( float x, float y );
102 bool isunordered( double x, double y );
103 bool isunordered( long double x, long double y );
105 #endif // __cplusplus
107 // --------------------------------------------------------------------------
112 // These functions return the magnitude of their parameter.
113 double abs( double x );
114 float abs( float x );
115 long double abs( long double x );
116 float fabs( float x );
117 long double fabs( long double x );
119 // These functions return the sine of their parameter.
120 float sin( float x );
121 long double sin( long double x );
123 // These functions return the hyperbolic sine of their parameter.
124 float sinh( float x );
125 long double sinh( long double x );
127 // These functions return the arcsine of their parameter.
128 float asin( float x );
129 long double asin( long double x );
131 // These functions compute the arc hyperbolic sine of x.
132 // @returns arsinh x.
133 float asinh( float x );
134 long double asinh( long double x );
136 // These functions return the cosine of their parameter.
137 float cos( float x );
138 long double cos( long double x );
140 // These functions return the hyperbolic cosine of their parameter.
141 float cosh( float x );
142 long double cosh( long double x );
144 // These functions return the arcsine of their parameter.
145 float acos( float x );
146 long double acos( long double x );
148 // These functions return the hyperbolic arccosine of their parameter.
149 float acosh( float x );
150 long double acosh( long double x );
152 // These functions return the tangent of their parameter.
153 float tan( float x );
154 long double tan( long double x );
156 // These functions return the hyperbolic tangent of their parameter.
157 float tanh( float x );
158 long double tanh( long double x );
160 // These functions return the arctangent of their parameter.
161 float atan( float x );
162 long double atan( long double x );
164 // These functions return the hyperbolic arctangent of their parameter.
165 float atanh( float x );
166 long double atanh( long double x );
169 float atan2( float y, float x );
170 long double atan2( long double y, long double x );
172 // These functions return sqrt( x^2 + y^2 ).
173 float hypot( float x, float y );
174 long double hypot( long double x, long double y );
176 // These functions return their parameter x, raised to the power y.
177 float pow( float x, float y );
178 long double pow( long double x, long double y );
179 double pow( double x, int y );
180 float pow( float x, int y );
181 long double pow( long double x, int y );
183 // These functions return the square root of their parameter.
184 float sqrt( float x );
185 long double sqrt( long double x );
188 float cbrt( float x );
189 long double cbrt( long double x );
192 float exp( float x );
193 long double exp( long double x );
196 float exp2( float x );
197 long double exp2( long double x );
200 float expm1( float x );
201 long double expm1( long double x );
204 float frexp( float x, int * exponent );
205 long double frexp( long double x, int * exponent );
208 float ldexp( float x, int exponent );
209 long double ldexp( long double x, int exponent );
211 // These functions return the natural logarithm of their parameter.
212 float log( float x );
213 long double log( long double x );
215 // These functions return the logarithm (base 10 ) of their parameter.
216 float log10( float x );
217 long double log10( long double x );
219 // These functions return the logarithm (base 2 ) of their parameter.
220 float log2( float x );
221 long double log2( long double x );
224 float logb( float x );
225 long double logb( long double x );
228 int ilogb( float x );
229 int ilogb( long double x );
232 float log1p( float x );
233 long double log1p( long double x );
235 // These functions return the smallest integer no larger than their parameter
236 float ceil( float x );
237 long double ceil( long double x );
239 // These functions return the biggest integer no larger than their parameter.
240 float floor( float x );
241 long double floor( long double x );
244 float fmod( float x, float y );
245 long double fmod( long double x, long double y );
248 float modf( float x, float * integer );
249 long double modf( long double x, long double * integer );
251 // These functions return their parameter x, with the sign of parameter y.
252 float copysign( float x, float y );
253 long double copysign( long double x, long double y );
256 float erf( float x );
257 long double erf( long double x );
260 float erfc( float x );
261 long double erfc( long double x );
264 float fdim( float x, float y );
265 long double fdim( long double x, long double y );
268 float fma( float x, float y, float z );
269 long double fma( long double x, long double y, long double z );
271 // These functions return the larger of their parameters.
272 float fmax( float x, float y );
273 long double fmax( long double x, long double y );
275 // These functions return the smaller of their parameters.
276 float fmin( float x, float y );
277 long double fmin( long double x, long double y );
280 long long llrint( float x );
281 long long llrint( long double x );
282 long lrint( float x );
283 long lrint( long double x );
284 float rint( float x );
285 long double rint( long double x );
288 long long llround( float x );
289 long long llround( long double x );
290 long lround( float x );
291 long lround( long double x );
292 float round( float x );
293 long double round( long double x );
296 float trunc( float x );
297 long double trunc( long double x );
300 float nearbyint( float x );
301 long double nearbyint( long double x );
304 float nextafter( float x, float y );
305 long double nextafter( long double x, long double y );
308 float nexttoward( float x, long double y );
309 long double nexttoward( long double x, long double y );
312 float remainder( float x, float y );
313 long double remainder( long double x, long double y );
316 float remquo( float x, float y, int * quotient );
317 long double remquo( long double x, long double y, int * quotient );
320 float scalbn( float x, int ex );
321 long double scalbn( long double x, int ex );
324 float scalbln( float x, long ex );
325 long double scalbln( long double x, long ex );
328 float lgamma( float x );
329 long double lgamma( long double x );
332 float tgamma( float x );
333 long double tgamma( long double x );
335 #endif // __cplusplus
337 // ----------------------------------------------------------------------------
338 // FUNCTIONS - Standard C
340 // These functions return the magnitude of their parameter.
341 double fabs( double x );
342 float fabsf( float x );
343 long double fabsl( long double x );
345 // These functions compute the sine of x (measured in radians).
347 double sin( double x );
348 float sinf( float x );
349 long double sinl( long double x );
351 // These functions return the hyperbolic cosine of their parameter.
352 double sinh( double x );
353 float sinhf( float x );
354 long double sinhl( long double x );
356 // These functions return the arcsine of their parameter.
357 double asin( double x );
358 float asinf( float x );
359 long double asinl( long double x );
361 // These functions return the hyperbolic arcsine of their parameter.
362 double asinh( double x );
363 float asinhf( float x );
364 long double asinhl( long double x );
366 // These functions compute the cosine of x (measured in radians).
368 double cos( double x );
369 float cosf( float x );
370 long double cosl( long double x );
372 // These functions return the hyperbolic cosine of their parameter.
373 double cosh( double x );
374 float coshf( float x );
375 long double coshl( long double x );
377 // These functions return the arccosine of their parameter.
378 double acos( double x );
379 float acosf( float x );
380 long double acosl( long double x );
382 // These functions return the hyperbolic arccosine of their parameter.
383 double acosh( double x );
384 float acoshf( float x );
385 long double acoshl( long double x );
387 // These functions return the tangent of x (measured in radians).
389 double tan( double x );
390 float tanf( float x );
391 long double tanl( long double x );
393 // These functions return the hyperbolic tangent of their parameter.
394 double tanh( double x );
395 float tanhf( float x );
396 long double tanhl( long double x );
398 // These functions compute the principal value of the arc tangent of x.
399 // @returns arctan x in the interval [-p/2, +p/2] radians.
400 double atan( double x );
401 float atanf( float x );
402 long double atanl( long double x );
404 // These functions return the hyperbolic arctangent of their parameter.
405 double atanh( double x );
406 float atanhf( float x );
407 long double atanhl( long double x );
410 double atan2( double y, double x );
411 float atan2f( float y, float x );
412 long double atan2l( long double y, long double x );
414 // These functions return sqrt(x^2 + y^2 ).
415 double hypot( double x, double y );
416 float hypotf( float x, float y );
417 long double hypotl( long double x, long double y );
419 // These functions return their parameter x, raised to the power y.
420 double pow( double x, double y );
421 float powf( float x, float y );
422 long double powl( long double x, long double y );
424 // These functions return the square root of their parameter.
425 double sqrt( double x );
426 float sqrtf( float x );
427 long double sqrtl( long double x );
430 double cbrt( double x );
431 float cbrtf( float x );
432 long double cbrtl( long double x );
435 double exp( double x );
436 float expf( float x );
437 long double expl( long double x );
440 double exp2( double x );
441 float exp2f( float x );
442 long double exp2l( long double x );
445 double expm1( double x );
446 float expm1f( float x );
447 long double expm1l( long double x );
450 double frexp( double x, int * exp );
451 float frexpf( float x, int * exp );
452 long double frexpl( long double x, int * exp );
455 double ldexp( double x, int exp );
456 float ldexpf( float x, int exp );
457 long double ldexpl( long double x, int exp );
459 // These functions return the natural logarithm of their parameter.
460 double log( double x );
461 float logf( float x );
462 long double logl( long double x );
464 // These functions return the logarithm (base 10 ) of their parameter.
465 double log10( double x );
466 float log10f( float x );
467 long double log10l( long double x );
469 // These functions return the logarithm (base 2 ) of their parameter.
470 double log2( double x );
471 float log2f( float x );
472 long double log2l( long double x );
475 double logb( double x );
476 float logbf( float x );
477 long double logbl( long double x );
480 int ilogb( double x );
481 int ilogbf( float x );
482 int ilogbl( long double x );
485 double log1p( double x );
486 float log1pf( float x );
487 long double log1pl( long double x );
489 // These functions return the smallest integer no smaller than value.
490 double ceil( double x );
491 float ceilf( float x );
492 long double ceill( long double x );
494 // These functions return the largest integer no larger than their parameter.
495 double floor( double x );
496 float floorf( float x );
497 long double floorl( long double x );
500 double fmod( double x, double y );
501 float fmodf( float x, float y );
502 long double fmodl( long double x, long double y );
505 double modf( double x, double * integer );
506 float modff( float x, float * integer );
507 long double modfl( long double x, long double * integer );
509 // These functions return their parameter x, with the sign of parameter y.
510 double copysign( double x, double y );
511 float copysignf( float x, float y );
512 long double copysignl( long double x, long double y );
515 double erf( double x );
516 float erff( float x );
517 long double erfl( long double x );
520 double erfc( double x );
521 float erfcf( float x );
522 long double erfcl( long double x );
525 double fdim( double x, double y );
526 float fdimf( float x, float y );
527 long double fdiml( long double x, long double y );
530 double fma( double x, double y, double z );
531 float fmaf( float x, float y, float z );
532 long double fmal( long double x, long double y, long double z );
534 // These functions return the larger of their parameters.
535 double fmax( double x, double y );
536 float fmaxf( float x, float y );
537 long double fmaxl( long double x, long double y );
539 // These functions return the smaller of their parameters.
540 double fmin( double x, double y );
541 float fminf( float x, float y );
542 long double fminl( long double x, long double y );
545 long long llrint( double x );
546 long long llrintf( float x );
547 long long llrintl( long double x );
548 long lrint( double x );
549 long lrintf( float x );
550 long lrintl( long double x );
551 double rint( double x );
552 float rintf( float x );
553 long double rintl( long double x );
556 long long llround( double x );
557 long long llroundf( float x );
558 long long llroundl( long double x );
559 long lround( double x );
560 long lroundf( float x );
561 long lroundl( long double x );
562 double round( double x );
563 float roundf( float x );
564 long double roundl( long double x );
567 double trunc( double x );
568 float truncf( float x );
569 long double truncl( long double x );
571 double nearbyint( double x );
572 float nearbyintf( float x );
573 long double nearbyintl( long double x );
575 double nextafter( double x, double y );
576 float nextafterf( float x, float y );
577 long double nextafterl( long double x, long double y );
580 double nexttoward( double x, long double y );
581 float nexttowardf( float x, long double y );
582 long double nexttowardl( long double x, long double y );
585 double remainder( double x, double y );
586 float remainderf( float x, float y );
587 long double remainderl( long double x, long double y );
590 double remquo( double x, double y, int * pquo );
591 float remquof( float x, float y, int * pquo );
592 long double remquol( long double x, long double y, int * pquo );
595 double scalbn( double x, int ex );
596 float scalbnf( float x, int ex );
597 long double scalbnl( long double x, int ex );
600 double scalbln( double x, long ex );
601 float scalblnf( float x, long ex );
602 long double scalblnl( long double x, long ex );
605 double lgamma( double x );
606 float lgammaf( float x );
607 long double lgammal( long double x );
610 double tgamma( double x );
611 float tgammaf( float x );
612 long double tgammal( long double x );
615 double nan( const char *str );
616 float nanf( const char *str );
617 long double nanl( const char *str );