]> pd.if.org Git - pdclib/blob - includes/math.h
Fleshing out the headers.
[pdclib] / includes / math.h
1 // ----------------------------------------------------------------------------
2 // $Id$
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 // ----------------------------------------------------------------------------
9
10 #ifndef __MATH_H
11 #define __MATH_H __MATH_H
12
13 // ----------------------------------------------------------------------------
14 // DEFINES
15
16 #define HUGE_VAL  // TODO
17 #define HUGE_VALF // TODO
18 #define HUGE_VALL // TODO
19
20 #define INFINITY // TODO
21 #define NAN      // TODO
22
23 #define FP_FAST_FMA  // TODO
24 #define FP_FAST_FMAF // TODO
25 #define FP_FAST_FMAL // TODO
26
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
32
33 #define FP_ILOGB0   // TODO
34 #define FP_ILOGBNAN // TODO
35
36 #define MATH_ERRNO       1
37 #define MATH_ERREXCEPT   2
38 #define math_errhandling // TODO
39
40 // --------------------------------------------------------------------------
41 // TYPEDEFS
42
43 typedef double_t; // TODO
44 typedef float_t;  // TODO
45
46 // --------------------------------------------------------------------------
47 // MACROS
48
49 #ifndef __cplusplus
50
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
57
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
64
65 #else // __cplusplus
66
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 );
104
105 #endif // __cplusplus
106
107 // --------------------------------------------------------------------------
108 // FUNCTIONS - C++
109
110 #ifdef __cplusplus
111
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 );
118
119 // These functions return the sine of their parameter.
120 float       sin( float       x );
121 long double sin( long double x );
122
123 // These functions return the hyperbolic sine of their parameter.
124 float       sinh( float       x );
125 long double sinh( long double x );
126
127 // These functions return the arcsine of their parameter.
128 float       asin( float       x );
129 long double asin( long double x );
130
131 // These functions return the hyperbolic arcsine of their parameter.
132 float       asinh( float       x );
133 long double asinh( long double x );
134
135 // These functions return the cosine of their parameter.
136 float       cos( float       x );
137 long double cos( long double x );
138
139 // These functions return the hyperbolic cosine of their parameter.
140 float       cosh( float       x );
141 long double cosh( long double x );
142
143 // These functions return the arccosine of their parameter.
144 float       acos( float       x );
145 long double acos( long double x );
146
147 // These functions return the hyperbolic arccosine of their parameter.
148 float       acosh( float       x );
149 long double acosh( long double x );
150
151 // These functions return the tangent of their parameter.
152 float       tan( float       x );
153 long double tan( long double x );
154
155 // These functions return the hyperbolic tangent of their parameter.
156 float       tanh( float       x );
157 long double tanh( long double x );
158
159 // These functions return the arctangent of their parameter.
160 float       atan( float       x );
161 long double atan( long double x );
162
163 // These functions return the hyperbolic arctangent of their parameter.
164 float       atanh( float       x );
165 long double atanh( long double x );
166
167 // TODO
168 float       atan2( float       x, float       y );
169 long double atan2( long double x, long double y );
170
171 // These functions return sqrt( x^2 + y^2 ).
172 float       hypot( float       x, float       y );
173 long double hypot( long double x, long double y );
174
175 // These functions return their parameter x, raised to the power y.
176 float       pow( float       x, float       y );
177 long double pow( long double x, long double y );
178 double      pow( double      x, int         y );
179 float       pow( float       x, int         y );
180 long double pow( long double x, int         y );
181
182 // These functions return the square root of their parameter.
183 float       sqrt( float       x );
184 long double sqrt( long double x );
185
186 // TODO
187 float       cbrt( float       x );
188 long double cbrt( long double x );
189
190 // TODO
191 float       exp( float       x );
192 long double exp( long double x );
193
194 // TODO
195 float       exp2( float       x );
196 long double exp2( long double x );
197
198 // TODO
199 float       expm1( float       x );
200 long double expm1( long double x );
201
202 // TODO
203 float       frexp( float       x, int * exponent );
204 long double frexp( long double x, int * exponent );
205
206 // TODO
207 float       ldexp( float       x, int exponent );
208 long double ldexp( long double x, int exponent );
209
210 // These functions return the natural logarithm of their parameter.
211 float       log( float       x );
212 long double log( long double x );
213
214 // These functions return the logarithm (base 10 ) of their parameter.
215 float       log10( float       x );
216 long double log10( long double x );
217
218 // These functions return the logarithm (base 2 ) of their parameter.
219 float       log2( float       x );
220 long double log2( long double x );
221
222 // TODO
223 float       logb( float       x );
224 long double logb( long double x );
225
226 // TODO
227 int ilogb( float       x );
228 int ilogb( long double x );
229
230 // TODO
231 float       log1p( float       x );
232 long double log1p( long double x );
233
234 // These functions return the smallest integer no larger than their parameter
235 float       ceil( float       x );
236 long double ceil( long double x );
237
238 // These functions return the biggest integer no larger than their parameter.
239 float       floor( float       x );
240 long double floor( long double x );
241
242 // TODO
243 float       fmod( float       x, float       y );
244 long double fmod( long double x, long double y );
245
246 // TODO
247 float       modf( float       x, float *       integer );
248 long double modf( long double x, long double * integer );
249
250 // These functions return their parameter x, with the sign of parameter y.
251 float       copysign( float       x, float       y );
252 long double copysign( long double x, long double y );
253
254 // TODO
255 float       erf( float       x );
256 long double erf( long double x );
257
258 // TODO
259 float       erfc( float       x );
260 long double erfc( long double x );
261
262 // TODO
263 float       fdim( float       x, float       y );
264 long double fdim( long double x, long double y );
265
266 // TODO
267 float       fma( float       x, float       y, float       z );
268 long double fma( long double x, long double y, long double z );
269
270 // These functions return the larger of their parameters.
271 float       fmax( float       x, float       y );
272 long double fmax( long double x, long double y );
273
274 // These functions return the smaller of their parameters.
275 float       fmin( float       x, float       y );
276 long double fmin( long double x, long double y );
277
278 // TODO
279 long long llrint( float x );
280 long long llrint( long double x );
281 long lrint( float       x );
282 long lrint( long double x );
283 float       rint( float       x );
284 long double rint( long double x );
285
286 // TODO
287 long long llround( float       x );
288 long long llround( long double x );
289 long lround( float       x );
290 long lround( long double x );
291 float       round( float       x );
292 long double round( long double x );
293
294 // TODO
295 float       trunc( float       x );
296 long double trunc( long double x );
297
298 // TODO
299 float       nearbyint( float       x );
300 long double nearbyint( long double x );
301
302 // TODO
303 float       nextafter( float       x, float       y );
304 long double nextafter( long double x, long double y );
305
306 // TODO
307 float       nexttoward( float       x, long double y );
308 long double nexttoward( long double x, long double y );
309
310 // TODO
311 float       remainder( float       x, float       y );
312 long double remainder( long double x, long double y );
313
314 // TODO
315 float       remquo( float       x, float       y, int * quotient );
316 long double remquo( long double x, long double y, int * quotient );
317
318 // TODO
319 float       scalbn( float       x, int ex );
320 long double scalbn( long double x, int ex );
321
322 // TODO
323 float       scalbln( float       x, long ex );
324 long double scalbln( long double x, long ex );
325
326 // TODO
327 float       lgamma( float       x );
328 long double lgamma( long double x );
329
330 // TODO
331 float       tgamma( float       x );
332 long double tgamma( long double x );
333
334 #endif // __cplusplus
335
336 // ----------------------------------------------------------------------------
337 // FUNCTIONS - Standard C
338
339 // These functions return the magnitude of its parameter.
340 double      fabs( double       x );
341 float       fabsf( float       x );
342 long double fabsl( long double x );
343
344 // These functions return the sine of its parameter.
345 double      sin( double       x );
346 float       sinf( float       x );
347 long double sinl( long double x );
348
349 // These functions return the hyperbolic cosine of its parameter.
350 double      sinh( double       x );
351 float       sinhf( float       x );
352 long double sinhl( long double x );
353
354 // These functions return the arcsine of its parameter.
355 double      asin( double       x );
356 float       asinf( float       x );
357 long double asinl( long double x );
358
359 // These functions return the hyperbolic arcsine of their parameter.
360 double      asinh( double       x );
361 float       asinhf( float       x );
362 long double asinhl( long double x );
363
364 // These functions return the cosine of its parameter.
365 double      cos( double       x );
366 float       cosf( float       x );
367 long double cosl( long double x );
368
369 // These functions return the hyperbolic cosine of its parameter.
370 double      cosh( double       x );
371 float       coshf( float       x );
372 long double coshl( long double x );
373
374 // These functions return the arccosine of its parameter.
375 double      acos( double       x );
376 float       acosf( float       x );
377 long double acosl( long double x );
378
379 // These functions return the hyperbolic arccosine of their parameter.
380 double      acosh( double       x );
381 float       acoshf( float       x );
382 long double acoshl( long double x );
383
384 // These functions return the tangent of its parameter.
385 double      tan( double       x );
386 float       tanf( float       x );
387 long double tanl( long double x );
388
389 // These functions return the hyperbolic tangent of its parameter.
390 double      tanh( double       x );
391 float       tanhf( float       x );
392 long double tanhl( long double x );
393
394 // These functions return the arctangent of its parameter.
395 double      atan( double       x );
396 float       atanf( float       x );
397 long double atanl( long double x );
398
399 // These functions return the hyperbolic arctangent of their parameter.
400 double      atanh( double       x );
401 float       atanhf( float       x );
402 long double atanhl( long double x );
403
404 // TODO
405 double      atan2( double       y, double      x );
406 float       atan2f( float       y, float       x );
407 long double atan2l( long double y, long double x );
408
409 // These functions return sqrt(x^2 + y^2 ).
410 double      hypot( double       x, double      y );
411 float       hypotf( float       x, float       y );
412 long double hypotl( long double x, long double y );
413
414 // These functions return its parameter x, raised to the power y.
415 double      pow( double       x, double      y );
416 float       powf( float       x, float       y );
417 long double powl( long double x, long double y );
418
419 // These functions return the square root of its parameter.
420 double      sqrt( double       x );
421 float       sqrtf( float       x );
422 long double sqrtl( long double x );
423
424 // TODO
425 double      cbrt( double       x );
426 float       cbrtf( float       x );
427 long double cbrtl( long double x );
428
429 // TODO
430 double      exp( double       x );
431 float       expf( float       x );
432 long double expl( long double x );
433
434 // TODO
435 double      exp2( double       x );
436 float       exp2f( float       x );
437 long double exp2l( long double x );
438
439 // TODO
440 double      expm1( double       x );
441 float       expm1f( float       x );
442 long double expm1l( long double x );
443
444 // TODO
445 double      frexp( double       x, int * exp );
446 float       frexpf( float       x, int * exp );
447 long double frexpl( long double x, int * exp );
448
449 // TODO
450 double      ldexp( double       x, int exp );
451 float       ldexpf( float       x, int exp );
452 long double ldexpl( long double x, int exp );
453
454 // These functions return the natural logarithm of its parameter.
455 double      log( double       x );
456 float       logf( float       x );
457 long double logl( long double x );
458
459 // These functions return the logarithm (base 10 ) of its parameter.
460 double      log10( double       x );
461 float       log10f( float       x );
462 long double log10l( long double x );
463
464 // These functions return the logarithm (base 2 ) of their parameter.
465 double      log2( double       x );
466 float       log2f( float       x );
467 long double log2l( long double x );
468
469 // TODO
470 double      logb( double       x );
471 float       logbf( float       x );
472 long double logbl( long double x );
473
474 // TODO
475 int ilogb( double       x );
476 int ilogbf( float       x );
477 int ilogbl( long double x );
478
479 // TODO
480 double      log1p( double       x );
481 float       log1pf( float       x );
482 long double log1pl( long double x );
483
484 // These functions return the smallest integer no smaller than value.
485 double      ceil( double       x );
486 float       ceilf( float       x );
487 long double ceill( long double x );
488
489 // These functions return the largest integer no larger than its parameter.
490 double      floor( double       x );
491 float       floorf( float       x );
492 long double floorl( long double x );
493
494 // TODO
495 double      fmod( double       x, double      y );
496 float       fmodf( float       x, float       y );
497 long double fmodl( long double x, long double y );
498
499 // TODO
500 double      modf( double       x, double *      integer );
501 float       modff( float       x, float *       integer );
502 long double modfl( long double x, long double * integer );
503
504 // These functions return their parameter x, with the sign of parameter y.
505 double      copysign( double       x, double      y );
506 float       copysignf( float       x, float       y );
507 long double copysignl( long double x, long double y );
508
509 // TODO
510 double      erf( double       x );
511 float       erff( float       x );
512 long double erfl( long double x );
513
514 // TODO
515 double      erfc( double       x );
516 float       erfcf( float       x );
517 long double erfcl( long double x );
518
519 // TODO
520 double      fdim( double       x, double      y );
521 float       fdimf( float       x, float       y );
522 long double fdiml( long double x, long double y );
523
524 // TODO
525 double      fma( double       x, double      y, double      z );
526 float       fmaf( float       x, float       y, float       z );
527 long double fmal( long double x, long double y, long double z );
528
529 // These functions return the larger of their parameters.
530 double      fmax( double       x, double      y );
531 float       fmaxf( float       x, float       y );
532 long double fmaxl( long double x, long double y );
533
534 // These functions return the smaller of their parameters.
535 double      fmin( double       x, double      y );
536 float       fminf( float       x, float       y );
537 long double fminl( long double x, long double y );
538
539 // TODO
540 long long llrint( double       x );
541 long long llrintf( float       x );
542 long long llrintl( long double x );
543 long lrint( double       x );
544 long lrintf( float       x );
545 long lrintl( long double x );
546 double      rint( double       x );
547 float       rintf( float       x );
548 long double rintl( long double x );
549
550 // TODO
551 long long llround( double       x );
552 long long llroundf( float       x );
553 long long llroundl( long double x );
554 long lround( double       x );
555 long lroundf( float       x );
556 long lroundl( long double x );
557 double      round( double       x );
558 float       roundf( float       x );
559 long double roundl( long double x );
560
561 // TODO
562 double      trunc( double       x );
563 float       truncf( float       x );
564 long double truncl( long double x );
565
566 double      nearbyint( double       x );
567 float       nearbyintf( float       x );
568 long double nearbyintl( long double x );
569
570 double      nextafter( double       x, double      y );
571 float       nextafterf( float       x, float       y );
572 long double nextafterl( long double x, long double y );
573
574 // TODO
575 double      nexttoward( double       x, long double y );
576 float       nexttowardf( float       x, long double y );
577 long double nexttowardl( long double x, long double y );
578
579 // TODO
580 double      remainder( double       x, double      y );
581 float       remainderf( float       x, float       y );
582 long double remainderl( long double x, long double y );
583
584 // TODO
585 double      remquo( double       x, double      y, int * pquo );
586 float       remquof( float       x, float       y, int * pquo );
587 long double remquol( long double x, long double y, int * pquo );
588
589 // TODO
590 double      scalbn( double       x, int ex );
591 float       scalbnf( float       x, int ex );
592 long double scalbnl( long double x, int ex );
593
594 // TODO
595 double      scalbln( double       x, long ex );
596 float       scalblnf( float       x, long ex );
597 long double scalblnl( long double x, long ex );
598
599 // TODO
600 double      lgamma( double       x );
601 float       lgammaf( float       x );
602 long double lgammal( long double x );
603
604 // TODO
605 double      tgamma( double       x );
606 float       tgammaf( float       x );
607 long double tgammal( long double x );
608
609 // TODO
610 double      nan( const char  *str );
611 float       nanf( const char *str );
612 long double nanl( const char *str );
613
614 #endif // __MATH_H