]> pd.if.org Git - pdclib/blob - includes/math.h
Initial load with header templates and some first declarations.
[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 f-type double_t; // TODO
44 typedef f-type 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 // These functions return the magnitude of their parameter.
111 double      abs(double      x);
112 float       abs(float       x);
113 long double abs(long double x);
114 float       fabs(float       x);
115 long double fabs(long double x);
116
117 // These functions return the sine of their parameter.
118 float       sin(float       x);
119 long double sin(long double x);
120
121 // These functions return the hyperbolic sine of their parameter.
122 float       sinh(float       x);
123 long double sinh(long double x);
124
125 // These functions return the arcsine of their parameter.
126 float       asin(float       x);
127 long double asin(long double x);
128
129 // These functions return the hyperbolic arcsine of their parameter.
130 float       asinh(float       x);
131 long double asinh(long double x);
132
133 // These functions return the cosine of their parameter.
134 float       cos(float       x);
135 long double cos(long double x);
136
137 // These functions return the hyperbolic cosine of their parameter.
138 float       cosh(float       x);
139 long double cosh(long double x);
140
141 // These functions return the arccosine of their parameter.
142 float       acos(float       x);
143 long double acos(long double x);
144
145 // These functions return the hyperbolic arccosine of their parameter.
146 float       acosh(float       x);
147 long double acosh(long double x);
148
149 // These functions return the tangent of their parameter.
150 float       tan(float       x);
151 long double tan(long double x);
152
153 // These functions return the hyperbolic tangent of their parameter.
154 float       tanh(float       x);
155 long double tanh(long double x);
156
157 // These functions return the arctangent of their parameter.
158 float       atan(float       x);
159 long double atan(long double x);
160
161 // These functions return the hyperbolic arctangent of their parameter.
162 float       atanh(float       x);
163 long double atanh(long double x);
164
165 // TODO
166 float       atan2(float       y, float       x);
167 long double atan2(long double y, long double x);
168
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);
172
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);
179
180 // These functions return the square root of their parameter.
181 float       sqrt(float       x);
182 long double sqrt(long double x);
183
184 // TODO
185 float       cbrt(float       x);
186 long double cbrt(long double x);
187
188 // TODO
189 float       exp(float       x);
190 long double exp(long double x);
191
192 // TODO
193 float       exp2(float       x);
194 long double exp2(long double x);
195
196 // TODO
197 float       expm1(float       x);
198 long double expm1(long double x);
199
200 // TODO
201 float       frexp(float       x, int * exponent);
202 long double frexp(long double x, int * exponent);
203
204 // TODO
205 float       ldexp(float       x, int exponent);
206 long double ldexp(long double x, int exponent);
207
208 // These functions return the natural logarithm of their parameter.
209 float       log(float       x);
210 long double log(long double x);
211
212 // These functions return the logarithm (base 10) of their parameter.
213 float       log10(float       x);
214 long double log10(long double x);
215
216 // These functions return the logarithm (base 2) of their parameter.
217 float       log2(float       x);
218 long double log2(long double x);
219
220 // TODO
221 float       logb(float       x);
222 long double logb(long double x);
223
224 // TODO
225 int ilogb(float       x);
226 int ilogb(long double x);
227
228 // TODO
229 float       log1p(float       x);
230 long double log1p(long double x);
231
232 // These functions return the smallest integer no larger than their parameter
233 float       ceil(float       x);
234 long double ceil(long double x);
235
236 // These functions return the biggest integer no larger than their parameter.
237 float       floor(float       x);
238 long double floor(long double x);
239
240 // TODO
241 float       fmod(float       x, float       y);
242 long double fmod(long double x, long double y);
243
244 // TODO
245 float       modf(float       x, float *       integer);
246 long double modf(long double x, long double * integer);
247
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);
251
252 // TODO
253 float       erf(float       x);
254 long double erf(long double x);
255
256 // TODO
257 float       erfc(float       x);
258 long double erfc(long double x);
259
260 // TODO
261 float       fdim(float       x, float       y);
262 long double fdim(long double x, long double y);
263
264 // TODO
265 float       fma(float       x, float       y, float       z);
266 long double fma(long double x, long double y, long double z);
267
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);
271
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);
275
276 // TODO
277 long long llrint(float x);
278 long long llrint(long double x);
279 long lrint(float       x);
280 long lrint(long double x);
281 float       rint(float       x);
282 long double rint(long double x);
283
284 // TODO
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);
291
292 // TODO
293 float       trunc(float       x);
294 long double trunc(long double x);
295
296 // TODO
297 float       nearbyint(float       x);
298 long double nearbyint(long double x);
299
300 // TODO
301 float       nextafter(float       x, float       y);
302 long double nextafter(long double x, long double y);
303
304 // TODO
305 float       nexttoward(float       x, long double y);
306 long double nexttoward(long double x, long double y);
307
308 // TODO
309 float       remainder(float       x, float       y);
310 long double remainder(long double x, long double y);
311
312 // TODO
313 float       remquo(float       x, float       y, int * quotient);
314 long double remquo(long double x, long double y, int * quotient);
315
316 // TODO
317 float       scalbn(float       x, int ex);
318 long double scalbn(long double x, int ex);
319
320 // TODO
321 float       scalbln(float       x, long ex);
322 long double scalbln(long double x, long ex);
323
324 // TODO
325 float       lgamma(float       x);
326 long double lgamma(long double x);
327
328 // TODO
329 float       tgamma(float       x);
330 long double tgamma(long double x);
331
332 // ----------------------------------------------------------------------------
333 // FUNCTIONS - Standard C
334
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);
339
340 // These functions return the sine of its parameter.
341 double      sin(double       x);
342 float       sinf(float       x);
343 long double sinl(long double x);
344
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);
349
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);
354
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);
359
360 // These functions return the cosine of its parameter.
361 double      cos(double       x);
362 float       cosf(float       x);
363 long double cosl(long double x);
364
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);
369
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);
374
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);
379
380 // These functions return the tangent of its parameter.
381 double      tan(double       x);
382 float       tanf(float       x);
383 long double tanl(long double x);
384
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);
389
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);
394
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);
399
400 // TODO
401 double      atan2(double       y, double      x);
402 float       atan2f(float       y, float       x);
403 long double atan2l(long double y, long double x);
404
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);
409
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);
414
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);
419
420 // TODO
421 double      cbrt(double       x);
422 float       cbrtf(float       x);
423 long double cbrtl(long double x);
424
425 // TODO
426 double      exp(double       x);
427 float       expf(float       x);
428 long double expl(long double x);
429
430 // TODO
431 double      exp2(double       x);
432 float       exp2f(float       x);
433 long double exp2l(long double x);
434
435 // TODO
436 double      expm1(double       x);
437 float       expm1f(float       x);
438 long double expm1l(long double x);
439
440 // TODO
441 double      frexp(double       x, int * exp);
442 float       frexpf(float       x, int * exp);
443 long double frexpl(long double x, int * exp);
444
445 // TODO
446 double      ldexp(double       x, int exp);
447 float       ldexpf(float       x, int exp);
448 long double ldexpl(long double x, int exp);
449
450 // These functions return the natural logarithm of its parameter.
451 double      log(double       x);
452 float       logf(float       x);
453 long double logl(long double x);
454
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);
459
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);
464
465 // TODO
466 double      logb(double       x);
467 float       logbf(float       x);
468 long double logbl(long double x);
469
470 // TODO
471 int ilogb(double       x);
472 int ilogbf(float       x);
473 int ilogbl(long double x);
474
475 // TODO
476 double      log1p(double       x);
477 float       log1pf(float       x);
478 long double log1pl(long double x);
479
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);
484
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);
489
490 // TODO
491 double      fmod(double       x, double      y);
492 float       fmodf(float       x, float       y);
493 long double fmodl(long double x, long double y);
494
495 // TODO
496 double      modf(double       x, double *      integer);
497 float       modff(float       x, float *       integer);
498 long double modfl(long double x, long double * integer);
499
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);
504
505 // TODO
506 double      erf(double       x);
507 float       erff(float       x);
508 long double erfl(long double x);
509
510 // TODO
511 double      erfc(double       x);
512 float       erfcf(float       x);
513 long double erfcl(long double x);
514
515 // TODO
516 double      fdim(double       x, double      y);
517 float       fdimf(float       x, float       y);
518 long double fdiml(long double x, long double y);
519
520 // TODO
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);
524
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);
529
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);
534
535 // TODO
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);
545
546 // TODO
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);
556
557 // TODO
558 double      trunc(double       x);
559 float       truncf(float       x);
560 long double truncl(long double x);
561
562 double      nearbyint(double       x);
563 float       nearbyintf(float       x);
564 long double nearbyintl(long double x);
565
566 double      nextafter(double       x, double      y);
567 float       nextafterf(float       x, float       y);
568 long double nextafterl(long double x, long double y);
569
570 // TODO
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);
574
575 // TODO
576 double      remainder(double       x, double      y);
577 float       remainderf(float       x, float       y);
578 long double remainderl(long double x, long double y);
579
580 // TODO
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);
584
585 // TODO
586 double      scalbn(double       x, int ex);
587 float       scalbnf(float       x, int ex);
588 long double scalbnl(long double x, int ex);
589
590 // TODO
591 double      scalbln(double       x, long ex);
592 float       scalblnf(float       x, long ex);
593 long double scalblnl(long double x, long ex);
594
595 // TODO
596 double      lgamma(double       x);
597 float       lgammaf(float       x);
598 long double lgammal(long double x);
599
600 // TODO
601 double      tgamma(double       x);
602 float       tgammaf(float       x);
603 long double tgammal(long double x);
604
605 // TODO
606 double      nan(const char  *str);
607 float       nanf(const char *str);
608 long double nanl(const char *str);
609
610 #endif // __MATH_H