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