]> pd.if.org Git - pdclib/blob - includes/math.h
Some cleanup.
[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 // Mathematics
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 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
59
60 #define isinf( x )             // TODO
61 #define isnan( x )             // TODO
62 #define isnormal( x )          // TODO
63 #define signbit( x )           // 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 compute the arc hyperbolic sine of x.
132 // @returns arsinh x.
133 float       asinh( float       x );
134 long double asinh( long double x );
135
136 // These functions return the cosine of their parameter.
137 float       cos( float       x );
138 long double cos( long double x );
139
140 // These functions return the hyperbolic cosine of their parameter.
141 float       cosh( float       x );
142 long double cosh( long double x );
143
144 // These functions return the arcsine of their parameter.
145 float       acos( float       x );
146 long double acos( long double x );
147
148 // These functions return the hyperbolic arccosine of their parameter.
149 float       acosh( float       x );
150 long double acosh( long double x );
151
152 // These functions return the tangent of their parameter.
153 float       tan( float       x );
154 long double tan( long double x );
155
156 // These functions return the hyperbolic tangent of their parameter.
157 float       tanh( float       x );
158 long double tanh( long double x );
159
160 // These functions return the arctangent of their parameter.
161 float       atan( float       x );
162 long double atan( long double x );
163
164 // These functions return the hyperbolic arctangent of their parameter.
165 float       atanh( float       x );
166 long double atanh( long double x );
167
168 // TODO
169 float       atan2( float       y, float       x );
170 long double atan2( long double y, long double x );
171
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 );
175
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 );
182
183 // These functions return the square root of their parameter.
184 float       sqrt( float       x );
185 long double sqrt( long double x );
186
187 // TODO
188 float       cbrt( float       x );
189 long double cbrt( long double x );
190
191 // TODO
192 float       exp( float       x );
193 long double exp( long double x );
194
195 // TODO
196 float       exp2( float       x );
197 long double exp2( long double x );
198
199 // TODO
200 float       expm1( float       x );
201 long double expm1( long double x );
202
203 // TODO
204 float       frexp( float       x, int * exponent );
205 long double frexp( long double x, int * exponent );
206
207 // TODO
208 float       ldexp( float       x, int exponent );
209 long double ldexp( long double x, int exponent );
210
211 // These functions return the natural logarithm of their parameter.
212 float       log( float       x );
213 long double log( long double x );
214
215 // These functions return the logarithm (base 10 ) of their parameter.
216 float       log10( float       x );
217 long double log10( long double x );
218
219 // These functions return the logarithm (base 2 ) of their parameter.
220 float       log2( float       x );
221 long double log2( long double x );
222
223 // TODO
224 float       logb( float       x );
225 long double logb( long double x );
226
227 // TODO
228 int ilogb( float       x );
229 int ilogb( long double x );
230
231 // TODO
232 float       log1p( float       x );
233 long double log1p( long double x );
234
235 // These functions return the smallest integer no larger than their parameter
236 float       ceil( float       x );
237 long double ceil( long double x );
238
239 // These functions return the biggest integer no larger than their parameter.
240 float       floor( float       x );
241 long double floor( long double x );
242
243 // TODO
244 float       fmod( float       x, float       y );
245 long double fmod( long double x, long double y );
246
247 // TODO
248 float       modf( float       x, float *       integer );
249 long double modf( long double x, long double * integer );
250
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 );
254
255 // TODO
256 float       erf( float       x );
257 long double erf( long double x );
258
259 // TODO
260 float       erfc( float       x );
261 long double erfc( long double x );
262
263 // TODO
264 float       fdim( float       x, float       y );
265 long double fdim( long double x, long double y );
266
267 // TODO
268 float       fma( float       x, float       y, float       z );
269 long double fma( long double x, long double y, long double z );
270
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 );
274
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 );
278
279 // TODO
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 );
286
287 // TODO
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 );
294
295 // TODO
296 float       trunc( float       x );
297 long double trunc( long double x );
298
299 // TODO
300 float       nearbyint( float       x );
301 long double nearbyint( long double x );
302
303 // TODO
304 float       nextafter( float       x, float       y );
305 long double nextafter( long double x, long double y );
306
307 // TODO
308 float       nexttoward( float       x, long double y );
309 long double nexttoward( long double x, long double y );
310
311 // TODO
312 float       remainder( float       x, float       y );
313 long double remainder( long double x, long double y );
314
315 // TODO
316 float       remquo( float       x, float       y, int * quotient );
317 long double remquo( long double x, long double y, int * quotient );
318
319 // TODO
320 float       scalbn( float       x, int ex );
321 long double scalbn( long double x, int ex );
322
323 // TODO
324 float       scalbln( float       x, long ex );
325 long double scalbln( long double x, long ex );
326
327 // TODO
328 float       lgamma( float       x );
329 long double lgamma( long double x );
330
331 // TODO
332 float       tgamma( float       x );
333 long double tgamma( long double x );
334
335 #endif // __cplusplus
336
337 // ----------------------------------------------------------------------------
338 // FUNCTIONS - Standard C
339
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 );
344
345 // These functions compute the sine of x (measured in radians).
346 // @returns sin x.
347 double      sin( double       x );
348 float       sinf( float       x );
349 long double sinl( long double x );
350
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 );
355
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 );
360
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 );
365
366 // These functions compute the cosine of x (measured in radians).
367 // @returns cos x.
368 double      cos( double       x );
369 float       cosf( float       x );
370 long double cosl( long double x );
371
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 );
376
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 );
381
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 );
386
387 // These functions return the tangent of x (measured in radians).
388 // @returns tan x.
389 double      tan( double       x );
390 float       tanf( float       x );
391 long double tanl( long double x );
392
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 );
397
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 );
403
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 );
408
409 // TODO
410 double      atan2( double       y, double      x );
411 float       atan2f( float       y, float       x );
412 long double atan2l( long double y, long double x );
413
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 );
418
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 );
423
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 );
428
429 // TODO
430 double      cbrt( double       x );
431 float       cbrtf( float       x );
432 long double cbrtl( long double x );
433
434 // TODO
435 double      exp( double       x );
436 float       expf( float       x );
437 long double expl( long double x );
438
439 // TODO
440 double      exp2( double       x );
441 float       exp2f( float       x );
442 long double exp2l( long double x );
443
444 // TODO
445 double      expm1( double       x );
446 float       expm1f( float       x );
447 long double expm1l( long double x );
448
449 // TODO
450 double      frexp( double       x, int * exp );
451 float       frexpf( float       x, int * exp );
452 long double frexpl( long double x, int * exp );
453
454 // TODO
455 double      ldexp( double       x, int exp );
456 float       ldexpf( float       x, int exp );
457 long double ldexpl( long double x, int exp );
458
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 );
463
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 );
468
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 );
473
474 // TODO
475 double      logb( double       x );
476 float       logbf( float       x );
477 long double logbl( long double x );
478
479 // TODO
480 int ilogb( double       x );
481 int ilogbf( float       x );
482 int ilogbl( long double x );
483
484 // TODO
485 double      log1p( double       x );
486 float       log1pf( float       x );
487 long double log1pl( long double x );
488
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 );
493
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 );
498
499 // TODO
500 double      fmod( double       x, double      y );
501 float       fmodf( float       x, float       y );
502 long double fmodl( long double x, long double y );
503
504 // TODO
505 double      modf( double       x, double *      integer );
506 float       modff( float       x, float *       integer );
507 long double modfl( long double x, long double * integer );
508
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 );
513
514 // TODO
515 double      erf( double       x );
516 float       erff( float       x );
517 long double erfl( long double x );
518
519 // TODO
520 double      erfc( double       x );
521 float       erfcf( float       x );
522 long double erfcl( long double x );
523
524 // TODO
525 double      fdim( double       x, double      y );
526 float       fdimf( float       x, float       y );
527 long double fdiml( long double x, long double y );
528
529 // TODO
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 );
533
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 );
538
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 );
543
544 // TODO
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 );
554
555 // TODO
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 );
565
566 // TODO
567 double      trunc( double       x );
568 float       truncf( float       x );
569 long double truncl( long double x );
570
571 double      nearbyint( double       x );
572 float       nearbyintf( float       x );
573 long double nearbyintl( long double x );
574
575 double      nextafter( double       x, double      y );
576 float       nextafterf( float       x, float       y );
577 long double nextafterl( long double x, long double y );
578
579 // TODO
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 );
583
584 // TODO
585 double      remainder( double       x, double      y );
586 float       remainderf( float       x, float       y );
587 long double remainderl( long double x, long double y );
588
589 // TODO
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 );
593
594 // TODO
595 double      scalbn( double       x, int ex );
596 float       scalbnf( float       x, int ex );
597 long double scalbnl( long double x, int ex );
598
599 // TODO
600 double      scalbln( double       x, long ex );
601 float       scalblnf( float       x, long ex );
602 long double scalblnl( long double x, long ex );
603
604 // TODO
605 double      lgamma( double       x );
606 float       lgammaf( float       x );
607 long double lgammal( long double x );
608
609 // TODO
610 double      tgamma( double       x );
611 float       tgammaf( float       x );
612 long double tgammal( long double x );
613
614 // TODO
615 double      nan( const char  *str );
616 float       nanf( const char *str );
617 long double nanl( const char *str );
618
619 #endif // __MATH_H