1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
7 // Provides floating point math functions.
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 f-type double_t; // TODO
44 typedef f-type float_t; // TODO
46 // --------------------------------------------------------------------------
51 #define signbit(x) // TODO
52 #define fpclassify(x) // TODO
53 #define isfinite(x) // TODO
54 #define isinf(x) // TODO
55 #define isnan(x) // TODO
56 #define isnormal(x) // TODO
58 #define isgreater(x, y) // TODO
59 #define isgreaterequal(x, y) // TODO
60 #define isless(x, y) // TODO
61 #define islessequal(x, y) // TODO
62 #define islessgreater(x, y) // TODO
63 #define isunordered(x, y) // 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 // --------------------------------------------------------------------------
110 // These functions return the magnitude of their parameter.
111 double abs(double x);
113 long double abs(long double x);
115 long double fabs(long double x);
117 // These functions return the sine of their parameter.
119 long double sin(long double x);
121 // These functions return the hyperbolic sine of their parameter.
123 long double sinh(long double x);
125 // These functions return the arcsine of their parameter.
127 long double asin(long double x);
129 // These functions return the hyperbolic arcsine of their parameter.
130 float asinh(float x);
131 long double asinh(long double x);
133 // These functions return the cosine of their parameter.
135 long double cos(long double x);
137 // These functions return the hyperbolic cosine of their parameter.
139 long double cosh(long double x);
141 // These functions return the arccosine of their parameter.
143 long double acos(long double x);
145 // These functions return the hyperbolic arccosine of their parameter.
146 float acosh(float x);
147 long double acosh(long double x);
149 // These functions return the tangent of their parameter.
151 long double tan(long double x);
153 // These functions return the hyperbolic tangent of their parameter.
155 long double tanh(long double x);
157 // These functions return the arctangent of their parameter.
159 long double atan(long double x);
161 // These functions return the hyperbolic arctangent of their parameter.
162 float atanh(float x);
163 long double atanh(long double x);
166 float atan2(float y, float x);
167 long double atan2(long double y, long double x);
169 // These functions return sqrt(x^2 + y^2).
170 float hypot(float x, float y);
171 long double hypot(long double x, long double y);
173 // These functions return their parameter x, raised to the power y.
174 float pow(float x, float y);
175 long double pow(long double x, long double y);
176 double pow(double x, int y);
177 float pow(float x, int y);
178 long double pow(long double x, int y);
180 // These functions return the square root of their parameter.
182 long double sqrt(long double x);
186 long double cbrt(long double x);
190 long double exp(long double x);
194 long double exp2(long double x);
197 float expm1(float x);
198 long double expm1(long double x);
201 float frexp(float x, int * exponent);
202 long double frexp(long double x, int * exponent);
205 float ldexp(float x, int exponent);
206 long double ldexp(long double x, int exponent);
208 // These functions return the natural logarithm of their parameter.
210 long double log(long double x);
212 // These functions return the logarithm (base 10) of their parameter.
213 float log10(float x);
214 long double log10(long double x);
216 // These functions return the logarithm (base 2) of their parameter.
218 long double log2(long double x);
222 long double logb(long double x);
226 int ilogb(long double x);
229 float log1p(float x);
230 long double log1p(long double x);
232 // These functions return the smallest integer no larger than their parameter
234 long double ceil(long double x);
236 // These functions return the biggest integer no larger than their parameter.
237 float floor(float x);
238 long double floor(long double x);
241 float fmod(float x, float y);
242 long double fmod(long double x, long double y);
245 float modf(float x, float * integer);
246 long double modf(long double x, long double * integer);
248 // These functions return their parameter x, with the sign of parameter y.
249 float copysign(float x, float y);
250 long double copysign(long double x, long double y);
254 long double erf(long double x);
258 long double erfc(long double x);
261 float fdim(float x, float y);
262 long double fdim(long double x, long double y);
265 float fma(float x, float y, float z);
266 long double fma(long double x, long double y, long double z);
268 // These functions return the larger of their parameters.
269 float fmax(float x, float y);
270 long double fmax(long double x, long double y);
272 // These functions return the smaller of their parameters.
273 float fmin(float x, float y);
274 long double fmin(long double x, long double y);
277 long long llrint(float x);
278 long long llrint(long double x);
280 long lrint(long double x);
282 long double rint(long double x);
285 long long llround(float x);
286 long long llround(long double x);
287 long lround(float x);
288 long lround(long double x);
289 float round(float x);
290 long double round(long double x);
293 float trunc(float x);
294 long double trunc(long double x);
297 float nearbyint(float x);
298 long double nearbyint(long double x);
301 float nextafter(float x, float y);
302 long double nextafter(long double x, long double y);
305 float nexttoward(float x, long double y);
306 long double nexttoward(long double x, long double y);
309 float remainder(float x, float y);
310 long double remainder(long double x, long double y);
313 float remquo(float x, float y, int * quotient);
314 long double remquo(long double x, long double y, int * quotient);
317 float scalbn(float x, int ex);
318 long double scalbn(long double x, int ex);
321 float scalbln(float x, long ex);
322 long double scalbln(long double x, long ex);
325 float lgamma(float x);
326 long double lgamma(long double x);
329 float tgamma(float x);
330 long double tgamma(long double x);
332 // ----------------------------------------------------------------------------
333 // FUNCTIONS - Standard C
335 // These functions return the magnitude of its parameter.
336 double fabs(double x);
337 float fabsf(float x);
338 long double fabsl(long double x);
340 // These functions return the sine of its parameter.
341 double sin(double x);
343 long double sinl(long double x);
345 // These functions return the hyperbolic cosine of its parameter.
346 double sinh(double x);
347 float sinhf(float x);
348 long double sinhl(long double x);
350 // These functions return the arcsine of its parameter.
351 double asin(double x);
352 float asinf(float x);
353 long double asinl(long double x);
355 // These functions return the hyperbolic arcsine of their parameter.
356 double asinh(double x);
357 float asinhf(float x);
358 long double asinhl(long double x);
360 // These functions return the cosine of its parameter.
361 double cos(double x);
363 long double cosl(long double x);
365 // These functions return the hyperbolic cosine of its parameter.
366 double cosh(double x);
367 float coshf(float x);
368 long double coshl(long double x);
370 // These functions return the arccosine of its parameter.
371 double acos(double x);
372 float acosf(float x);
373 long double acosl(long double x);
375 // These functions return the hyperbolic arccosine of their parameter.
376 double acosh(double x);
377 float acoshf(float x);
378 long double acoshl(long double x);
380 // These functions return the tangent of its parameter.
381 double tan(double x);
383 long double tanl(long double x);
385 // These functions return the hyperbolic tangent of its parameter.
386 double tanh(double x);
387 float tanhf(float x);
388 long double tanhl(long double x);
390 // These functions return the arctangent of its parameter.
391 double atan(double x);
392 float atanf(float x);
393 long double atanl(long double x);
395 // These functions return the hyperbolic arctangent of their parameter.
396 double atanh(double x);
397 float atanhf(float x);
398 long double atanhl(long double x);
401 double atan2(double y, double x);
402 float atan2f(float y, float x);
403 long double atan2l(long double y, long double x);
405 // These functions return sqrt(x^2 + y^2).
406 double hypot(double x, double y);
407 float hypotf(float x, float y);
408 long double hypotl(long double x, long double y);
410 // These functions return its parameter x, raised to the power y.
411 double pow(double x, double y);
412 float powf(float x, float y);
413 long double powl(long double x, long double y);
415 // These functions return the square root of its parameter.
416 double sqrt(double x);
417 float sqrtf(float x);
418 long double sqrtl(long double x);
421 double cbrt(double x);
422 float cbrtf(float x);
423 long double cbrtl(long double x);
426 double exp(double x);
428 long double expl(long double x);
431 double exp2(double x);
432 float exp2f(float x);
433 long double exp2l(long double x);
436 double expm1(double x);
437 float expm1f(float x);
438 long double expm1l(long double x);
441 double frexp(double x, int * exp);
442 float frexpf(float x, int * exp);
443 long double frexpl(long double x, int * exp);
446 double ldexp(double x, int exp);
447 float ldexpf(float x, int exp);
448 long double ldexpl(long double x, int exp);
450 // These functions return the natural logarithm of its parameter.
451 double log(double x);
453 long double logl(long double x);
455 // These functions return the logarithm (base 10) of its parameter.
456 double log10(double x);
457 float log10f(float x);
458 long double log10l(long double x);
460 // These functions return the logarithm (base 2) of their parameter.
461 double log2(double x);
462 float log2f(float x);
463 long double log2l(long double x);
466 double logb(double x);
467 float logbf(float x);
468 long double logbl(long double x);
473 int ilogbl(long double x);
476 double log1p(double x);
477 float log1pf(float x);
478 long double log1pl(long double x);
480 // These functions return the smallest integer no smaller than value.
481 double ceil(double x);
482 float ceilf(float x);
483 long double ceill(long double x);
485 // These functions return the largest integer no larger than its parameter.
486 double floor(double x);
487 float floorf(float x);
488 long double floorl(long double x);
491 double fmod(double x, double y);
492 float fmodf(float x, float y);
493 long double fmodl(long double x, long double y);
496 double modf(double x, double * integer);
497 float modff(float x, float * integer);
498 long double modfl(long double x, long double * integer);
500 // These functions return their parameter x, with the sign of parameter y.
501 double copysign(double x, double y);
502 float copysignf(float x, float y);
503 long double copysignl(long double x, long double y);
506 double erf(double x);
508 long double erfl(long double x);
511 double erfc(double x);
512 float erfcf(float x);
513 long double erfcl(long double x);
516 double fdim(double x, double y);
517 float fdimf(float x, float y);
518 long double fdiml(long double x, long double y);
521 double fma(double x, double y, double z);
522 float fmaf(float x, float y, float z);
523 long double fmal(long double x, long double y, long double z);
525 // These functions return the larger of their parameters.
526 double fmax(double x, double y);
527 float fmaxf(float x, float y);
528 long double fmaxl(long double x, long double y);
530 // These functions return the smaller of their parameters.
531 double fmin(double x, double y);
532 float fminf(float x, float y);
533 long double fminl(long double x, long double y);
536 long long llrint(double x);
537 long long llrintf(float x);
538 long long llrintl(long double x);
539 long lrint(double x);
540 long lrintf(float x);
541 long lrintl(long double x);
542 double rint(double x);
543 float rintf(float x);
544 long double rintl(long double x);
547 long long llround(double x);
548 long long llroundf(float x);
549 long long llroundl(long double x);
550 long lround(double x);
551 long lroundf(float x);
552 long lroundl(long double x);
553 double round(double x);
554 float roundf(float x);
555 long double roundl(long double x);
558 double trunc(double x);
559 float truncf(float x);
560 long double truncl(long double x);
562 double nearbyint(double x);
563 float nearbyintf(float x);
564 long double nearbyintl(long double x);
566 double nextafter(double x, double y);
567 float nextafterf(float x, float y);
568 long double nextafterl(long double x, long double y);
571 double nexttoward(double x, long double y);
572 float nexttowardf(float x, long double y);
573 long double nexttowardl(long double x, long double y);
576 double remainder(double x, double y);
577 float remainderf(float x, float y);
578 long double remainderl(long double x, long double y);
581 double remquo(double x, double y, int * pquo);
582 float remquof(float x, float y, int * pquo);
583 long double remquol(long double x, long double y, int * pquo);
586 double scalbn(double x, int ex);
587 float scalbnf(float x, int ex);
588 long double scalbnl(long double x, int ex);
591 double scalbln(double x, long ex);
592 float scalblnf(float x, long ex);
593 long double scalblnl(long double x, long ex);
596 double lgamma(double x);
597 float lgammaf(float x);
598 long double lgammal(long double x);
601 double tgamma(double x);
602 float tgammaf(float x);
603 long double tgammal(long double x);
606 double nan(const char *str);
607 float nanf(const char *str);
608 long double nanl(const char *str);