Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

fxmath.h
1 /********************************************************************************
2 * *
3 * M a t h F u n c t i o n s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2015,2025 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXMATH_H
22 #define FXMATH_H
23 
24 // Remove macros
25 #undef fabs
26 #undef fabsf
27 #undef fmod
28 #undef fmodf
29 
30 #undef ceil
31 #undef ceilf
32 #undef floor
33 #undef floorf
34 #undef round
35 #undef roundf
36 #undef trunc
37 #undef truncf
38 #undef nearbyint
39 #undef nearbyintf
40 #undef rint
41 #undef rintf
42 
43 #undef sin
44 #undef sinf
45 #undef cos
46 #undef cosf
47 #undef tan
48 #undef tanf
49 #undef asin
50 #undef asinf
51 #undef acos
52 #undef acosf
53 #undef atan
54 #undef atanf
55 #undef atan2
56 #undef atan2f
57 #undef sincos
58 #undef sincosf
59 #undef sinh
60 #undef sinhf
61 #undef cosh
62 #undef coshf
63 #undef tanh
64 #undef tanhf
65 #undef asinh
66 #undef asinhf
67 #undef acosh
68 #undef acoshf
69 #undef atanh
70 #undef atanhf
71 
72 #undef pow
73 #undef powf
74 #undef pow10
75 #undef pow10f
76 #undef exp
77 #undef expf
78 #undef expm1
79 #undef expm1f
80 #undef exp2
81 #undef exp2f
82 #undef exp10
83 #undef exp10f
84 #undef log
85 #undef logf
86 #undef log1p
87 #undef log1pf
88 #undef log2
89 #undef log2f
90 #undef log10
91 #undef log10f
92 
93 #undef sqrt
94 #undef sqrtf
95 #undef cbrt
96 #undef cbrtf
97 #undef sqr
98 #undef sqrf
99 #undef cub
100 #undef cubf
101 
102 #undef max
103 #undef min
104 #undef fmax
105 #undef fmaxf
106 #undef fmin
107 #undef fminf
108 #undef copysign
109 #undef copysignf
110 #undef hypot
111 #undef hypotf
112 
113 
114 // Switch on remedial math on Windows with VC++
115 #if defined(WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))
116 #define NO_CEILF
117 #define NO_FLOORF
118 #define NO_ROUNDF
119 #define NO_ROUND
120 #define NO_TRUNCF
121 #define NO_TRUNC
122 #define NO_NEARBYINTF
123 #define NO_NEARBYINT
124 #define NO_RINTF
125 #define NO_RINT
126 #define NO_EXPM1F
127 #define NO_EXPM1
128 #define NO_EXP2F
129 #define NO_EXP2
130 #define NO_EXP10F
131 #define NO_EXP10
132 #define NO_POW10F
133 #define NO_POW10
134 #define NO_LOG1PF
135 #define NO_LOG1P
136 #define NO_LOG2F
137 #define NO_LOG2
138 #define NO_CBRTF
139 #define NO_CBRT
140 #define NO_SINHF
141 #define NO_SINH
142 #define NO_COSHF
143 #define NO_COSH
144 #define NO_TANHF
145 #define NO_TANH
146 #define NO_ASINHF
147 #define NO_ASINH
148 #define NO_ACOSHF
149 #define NO_ACOSH
150 #define NO_ATANHF
151 #define NO_ATANH
152 #define NO_FMAXF
153 #define NO_FMAX
154 #define NO_FMINF
155 #define NO_FMIN
156 #define NO_COPYSIGNF
157 #define NO_COPYSIGN
158 #define NO_HYPOTF
159 #define NO_HYPOT
160 #define NO_FDIMF
161 #define NO_FDIM
162 #define NO_SINCOS
163 #define NO_SINCOSF
164 #define NO_LRINT
165 #define NO_LRINTF
166 #endif
167 
168 // Systems below are missing these functions
169 #if defined(__sun__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
170 #define NO_EXP10F
171 #define NO_EXP10
172 #endif
173 
174 // Apple is missing sincos
175 #if defined(__APPLE__)
176 #define NO_SINCOS
177 #define NO_SINCOSF
178 #endif
179 
180 
181 namespace FX {
182 
183 /********************************* Constants *********************************/
184 
186 const FXdouble PI=3.1415926535897932384626433833;
187 
189 const FXdouble EULER=2.7182818284590452353602874713;
190 
192 const FXdouble DTOR=0.0174532925199432957692369077;
193 
195 const FXdouble RTOD=57.295779513082320876798154814;
196 
198 const FXdouble FEIGENBAUM=4.6692016091029906718532038215;
199 
201 const FXdouble GOLDENRATIO=1.6180339887498948482045868343;
202 
203 /********************************* Functions *********************************/
204 
205 // FOX math functions live here
206 namespace Math {
207 
208 
210 static inline FXuint fpBits(FXfloat x){
211  union{ FXfloat f; FXuint u; } z={x};
212  return z.u;
213  }
214 
216 static inline FXulong fpBits(FXdouble x){
217  union{ FXdouble f; FXulong u; } z={x};
218  return z.u;
219  }
220 
221 
223 static inline FXfloat fpFlt(FXuint bits){
224  union{ FXuint u; FXfloat f; } z={bits};
225  return z.f;
226  }
227 
229 static inline FXdouble fpFlt(FXulong bits){
230  union{ FXulong u; FXdouble f; } z={bits};
231  return z.f;
232  }
233 
234 
236 static inline FXfloat fpMake(FXuint mantissa,FXuint exponent=127,FXuint sign=0){
237  return fpFlt((mantissa&0x007fffff) | ((exponent&0xff)<<23) | (sign<<31));
238  }
239 
241 static inline FXdouble fpMake(FXulong mantissa,FXulong exponent=1023,FXulong sign=0){
242  return fpFlt((mantissa&FXLONG(0x000fffffffffffff)) | ((exponent&FXLONG(0x7ff))<<52) | (sign<<63));
243  }
244 
245 
247 static inline FXint fpSign(FXfloat x){
248  FXint sign=fpBits(x)>>31;
249  return sign;
250  }
251 
253 static inline FXlong fpSign(FXdouble x){
254  FXlong sign=fpBits(x)>>63;
255  return sign;
256  }
257 
258 
260 static inline FXint fpExponent(FXfloat x){
261  FXint exponent=(fpBits(x)>>23)&0xff;
262  FXint bias=126-(-exponent>>31);
263  return exponent-bias;
264  }
265 
267 static inline FXlong fpExponent(FXdouble x){
268  FXlong exponent=(fpBits(x)>>52)&0x7ff;
269  FXlong bias=1022-(-exponent>>63);
270  return exponent-bias;
271  }
272 
273 
275 static inline FXint fpMantissa(FXfloat x){
276  FXint mantissa=fpBits(x)&0x007fffff;
277  FXint exponent=fpBits(x)&0x7f800000;
278  FXint extrabit=-(-exponent>>31); // 1 if exponent!=0
279  return mantissa|(extrabit<<23);
280  }
281 
283 static inline FXlong fpMantissa(FXdouble x){
284  FXlong mantissa=fpBits(x)&FXLONG(0x000fffffffffffff);
285  FXlong exponent=fpBits(x)&FXLONG(0x7ff0000000000000);
286  FXlong extrabit=-(-exponent>>63); // 1 if exponent!=0
287  return mantissa|(extrabit<<52);
288  }
289 
290 
292 static inline FXbool fpFinite(FXfloat x){
293  return ((fpBits(x)&0x7fffffff)<0x7f800000);
294  }
295 
297 static inline FXbool fpFinite(FXdouble x){
298  return ((fpBits(x)&FXULONG(0x7fffffffffffffff))<FXULONG(0x7ff0000000000000));
299  }
300 
301 
303 static inline FXbool fpInfinite(FXfloat x){
304  return ((fpBits(x)&0x7fffffff)==0x7f800000);
305  }
306 
308 static inline FXbool fpInfinite(FXdouble x){
309  return ((fpBits(x)&FXULONG(0x7fffffffffffffff))==FXULONG(0x7ff0000000000000));
310  }
311 
312 
314 static inline FXbool fpNan(FXfloat x){
315  return (0x7f800000<(fpBits(x)&0x7fffffff));
316  }
317 
319 static inline FXbool fpNan(FXdouble x){
320  return (FXULONG(0x7ff0000000000000)<(fpBits(x)&FXULONG(0x7fffffffffffffff)));
321  }
322 
323 
325 static inline FXbool fpNormal(FXfloat x){
326  FXuint bits=fpBits(x)&0x7fffffff;
327  return bits==0 || (0x00800000<=bits && bits<0x7f800000);
328  }
329 
331 static inline FXbool fpNormal(FXdouble x){
332  FXulong bits=fpBits(x)&FXULONG(0x7fffffffffffffff);
333  return (bits==0) || ((FXULONG(0x0010000000000000)<=bits) && (bits<FXULONG(0x7ff0000000000000)));
334  }
335 
336 
338 static inline FXint iblend(FXint a,FXint b,FXint x,FXint y){
339  return a<b ? x : y;
340  }
341 
343 static inline FXlong iblend(FXlong a,FXlong b,FXlong x,FXlong y){
344  return a<b ? x : y;
345  }
346 
347 
349 static inline FXint imin(FXint x,FXint y){
350  return (x<y)?x:y;
351  }
352 
354 static inline FXuint imin(FXuint x,FXuint y){
355  return (x<y)?x:y;
356  }
357 
359 static inline FXlong imin(FXlong x,FXlong y){
360  return (x<y)?x:y;
361  }
362 
364 static inline FXulong imin(FXulong x,FXulong y){
365  return (x<y)?x:y;
366  }
367 
368 
370 static inline FXint imax(FXint x,FXint y){
371  return (x>y)?x:y;
372  }
373 
375 static inline FXuint imax(FXuint x,FXuint y){
376  return (x>y)?x:y;
377  }
378 
379 
381 static inline FXlong imax(FXlong x,FXlong y){
382  return (x>y)?x:y;
383  }
384 
386 static inline FXulong imax(FXulong x,FXulong y){
387  return (x>y)?x:y;
388  }
389 
390 
392 static inline FXshort iabs(FXshort x){
393  return 0<x?x:-x;
394  }
395 
397 static inline FXint iabs(FXint x){
398  return 0<x?x:-x;
399  }
400 
402 static inline FXlong iabs(FXlong x){
403  return 0<x?x:-x;
404  }
405 
406 
408 static inline FXint iclamp(FXint lo,FXint x,FXint hi){
409  return Math::imin(Math::imax(x,lo),hi);
410  }
411 
413 static inline FXlong iclamp(FXlong lo,FXlong x,FXlong hi){
414  return Math::imin(Math::imax(x,lo),hi);
415  }
416 
417 
419 static inline FXint iclamp(FXint x,FXint lim){
420  return imin(imax(x,-lim),lim);
421  }
422 
424 static inline FXlong iclamp(FXlong x,FXlong lim){
425  return imin(imax(x,-lim),lim);
426  }
427 
428 
430 static inline FXint isign(FXint x){
431  return (x>0)-(x<0);
432  }
433 
435 static inline FXlong isign(FXlong x){
436  return (x>0)-(x<0);
437  }
438 
439 
441 static inline FXfloat fmin(FXfloat x,FXfloat y){
442 #if defined(NO_FMINF)
443  return (x<y)?x:y;
444 #else
445  return ::fminf(x,y);
446 #endif
447  }
448 
449 
451 static inline FXdouble fmin(FXdouble x,FXdouble y){
452 #if defined(NO_FMIN)
453  return (x<y)?x:y;
454 #else
455  return ::fmin(x,y);
456 #endif
457  }
458 
459 
461 static inline FXfloat fmax(FXfloat x,FXfloat y){
462 #if defined(NO_FMAXF)
463  return (x>y)?x:y;
464 #else
465  return ::fmaxf(x,y);
466 #endif
467  }
468 
470 static inline FXdouble fmax(FXdouble x,FXdouble y){
471 #if defined(NO_FMAX)
472  return (x>y)?x:y;
473 #else
474  return ::fmax(x,y);
475 #endif
476  }
477 
478 
480 static inline FXfloat fabs(FXfloat x){
481 #if defined(NO_FABSF)
482  return (x<0.0f) ? -x : x;
483 #else
484  return ::fabsf(x);
485 #endif
486  }
487 
489 static inline FXdouble fabs(FXdouble x){
490  return ::fabs(x);
491  }
492 
493 
495 static inline FXfloat fclamp(FXfloat lo,FXfloat x,FXfloat hi){
496  return Math::fmin(Math::fmax(x,lo),hi);
497  }
498 
500 static inline FXdouble fclamp(FXdouble lo,FXdouble x,FXdouble hi){
501  return Math::fmin(Math::fmax(x,lo),hi);
502  }
503 
504 
506 static inline FXfloat fclamp(FXfloat x,FXfloat lim){
507  return fmin(fmax(x,-lim),lim);
508  }
509 
511 static inline FXdouble fclamp(FXdouble x,FXdouble lim){
512  return fmin(fmax(x,-lim),lim);
513  }
514 
515 
517 static inline FXfloat fdim(FXfloat x,FXfloat y){
518 #if defined(NO_FDIMF)
519  return Math::fmax(x-y,0.0f);
520 #else
521  return ::fdimf(x,y);
522 #endif
523  }
524 
526 static inline FXdouble fdim(FXdouble x,FXdouble y){
527 #if defined(NO_FDIM)
528  return Math::fmax(x-y,0.0);
529 #else
530  return ::fdim(x,y);
531 #endif
532  }
533 
534 
536 static inline FXfloat fmod(FXfloat x,FXfloat y){
537  return ::fmodf(x,y);
538  }
539 
541 static inline FXdouble fmod(FXdouble x,FXdouble y){
542  return ::fmod(x,y);
543  }
544 
545 
547 static inline FXfloat fblend(FXfloat a,FXfloat b,FXfloat x,FXfloat y){
548  return a<b ? x : y;
549  }
550 
551 
553 static inline FXdouble fblend(FXdouble a,FXdouble b,FXdouble x,FXdouble y){
554  return a<b ? x : y;
555  }
556 
557 
559 static inline FXfloat copysign(FXfloat x,FXfloat y){
560 #if defined(NO_COPYSIGNF)
561  union{ FXfloat f; FXuint u; } xx={x},yy={y};
562  xx.u&=0x7fffffff;
563  xx.u|=(yy.u&0x80000000);
564  return xx.f;
565 #else
566  return ::copysignf(x,y);
567 #endif
568  }
569 
571 static inline FXdouble copysign(FXdouble x,FXdouble y){
572 #if defined(NO_COPYSIGN)
573  union{ FXdouble f; FXulong u; } xx={x},yy={y};
574  xx.u&=FXULONG(0x7fffffffffffffff);
575  xx.u|=(yy.u&FXULONG(0x8000000000000000));
576  return xx.f;
577 #else
578  return ::copysign(x,y);
579 #endif
580  }
581 
582 
584 #if defined(NO_CEILF)
585 extern FXAPI FXfloat ceil(FXfloat x);
586 #else
587 static inline FXfloat ceil(FXfloat x){ return ::ceilf(x); }
588 #endif
589 
591 static inline FXdouble ceil(FXdouble x){ return ::ceil(x); }
592 
593 
595 #if defined(NO_FLOORF)
596 extern FXAPI FXfloat floor(FXfloat x);
597 #else
598 static inline FXfloat floor(FXfloat x){ return ::floorf(x); }
599 #endif
600 
602 static inline FXdouble floor(FXdouble x){ return ::floor(x); }
603 
605 #if defined(NO_ROUNDF)
606 extern FXAPI FXfloat round(FXfloat x);
607 #else
608 static inline FXfloat round(FXfloat x){ return ::roundf(x); }
609 #endif
610 
612 #if defined(NO_ROUND)
613 extern FXAPI FXdouble round(FXdouble x);
614 #else
615 static inline FXdouble round(FXdouble x){ return ::round(x); }
616 #endif
617 
618 
620 #if defined(NO_TRUNCF)
621 extern FXAPI FXfloat trunc(FXfloat x);
622 #else
623 static inline FXfloat trunc(FXfloat x){ return ::truncf(x); }
624 #endif
625 
627 #if defined(NO_TRUNC)
628 extern FXAPI FXdouble trunc(FXdouble x);
629 #else
630 static inline FXdouble trunc(FXdouble x){ return ::trunc(x); }
631 #endif
632 
633 
635 #if defined(NO_NEARBYINTF)
636 extern FXAPI FXfloat nearbyint(FXfloat x);
637 #else
638 static inline FXfloat nearbyint(FXfloat x){ return ::nearbyintf(x); }
639 #endif
640 
642 #if defined(NO_NEARBYINT)
643 extern FXAPI FXdouble nearbyint(FXdouble x);
644 #else
645 static inline FXdouble nearbyint(FXdouble x){ return ::nearbyint(x); }
646 #endif
647 
649 #if defined(NO_RINTF)
650 extern FXAPI FXfloat rint(FXfloat x);
651 #else
652 static inline FXfloat rint(FXfloat x){ return ::rintf(x); }
653 #endif
654 
656 #if defined(NO_RINT)
657 extern FXAPI FXdouble rint(FXdouble x);
658 #else
659 static inline FXdouble rint(FXdouble x){ return ::rint(x); }
660 #endif
661 
662 
664 static inline FXint lrint(FXfloat x){
665 #if defined(NO_LRINTF)
666  return (FXint)(x+Math::copysign(0.5f,x));
667 #else
668  return (FXint)::lrintf(x);
669 #endif
670  }
671 
673 static inline FXlong lrint(FXdouble x){
674 #if defined(NO_LRINT)
675  return (FXlong)(x+Math::copysign(0.5,x));
676 #else
677  return (FXlong)::lrint(x);
678 #endif
679  }
680 
681 
683 static inline FXfloat wrap(FXfloat x){
684 #if defined(__SSE4_1__)
685  return x-Math::nearbyint(x*0.159154943091895335768883763373f)*6.28318530717958647692528676656f;
686 #else
687  return x-Math::lrint(x*0.159154943091895335768883763373f)*6.28318530717958647692528676656f;
688 #endif
689  }
690 
692 static inline FXdouble wrap(FXdouble x){
693 #if defined(__SSE4_1__)
694  return x-Math::nearbyint(x*0.159154943091895335768883763373)*6.28318530717958647692528676656;
695 #else
696  return x-Math::lrint(x*0.159154943091895335768883763373)*6.28318530717958647692528676656;
697 #endif
698  }
699 
700 
702 static inline FXfloat wrap4(FXfloat x){
703  return x-Math::floor(x*0.159154943091895335768883763373f)*6.28318530717958647692528676656f;
704  }
705 
706 
708 static inline FXdouble wrap4(FXdouble x){
709  return x-Math::floor(x*0.159154943091895335768883763373)*6.28318530717958647692528676656;
710  }
711 
712 
714 static inline FXfloat stepify(FXfloat x,FXfloat s){
715  return Math::nearbyint(x/s)*s;
716  }
717 
719 static inline FXdouble stepify(FXdouble x,FXdouble s){
720  return Math::nearbyint(x/s)*s;
721  }
722 
723 
725 static inline FXfloat zigzag(FXfloat x){
726  return Math::fabs(2.0f*(x-Math::nearbyint(x)));
727  }
728 
730 static inline FXdouble zigzag(FXdouble x){
731  return Math::fabs(2.0*(x-Math::nearbyint(x)));
732  }
733 
734 
736 static inline FXfloat sawtooth(FXfloat x){
737  return x-Math::floor(x);
738  }
739 
741 static inline FXdouble sawtooth(FXdouble x){
742  return x-Math::floor(x);
743  }
744 
745 
747 static inline FXfloat rsawtooth(FXfloat x){
748  return Math::ceil(x)-x;
749  }
750 
752 static inline FXdouble rsawtooth(FXdouble x){
753  return Math::ceil(x)-x;
754  }
755 
756 
758 static inline FXfloat sin(FXfloat x){
759  return ::sinf(x);
760  }
761 
763 static inline FXdouble sin(FXdouble x){
764  return ::sin(x);
765  }
766 
767 
769 static inline FXfloat cos(FXfloat x){
770  return ::cosf(x);
771  }
772 
774 static inline FXdouble cos(FXdouble x){
775  return ::cos(x);
776  }
777 
778 
780 static inline FXfloat tan(FXfloat x){
781  return ::tanf(x);
782  }
783 
785 static inline FXdouble tan(FXdouble x){
786  return ::tan(x);
787  }
788 
789 
791 static inline FXfloat asin(FXfloat x){
792  return ::asinf(x);
793  }
794 
796 static inline FXdouble asin(FXdouble x){
797  return ::asin(x);
798  }
799 
800 
802 static inline FXfloat acos(FXfloat x){
803  return ::acosf(x);
804  }
805 
807 static inline FXdouble acos(FXdouble x){
808  return ::acos(x);
809  }
810 
811 
813 static inline FXfloat atan(FXfloat x){
814  return ::atanf(x);
815  }
816 
818 static inline FXdouble atan(FXdouble x){
819  return ::atan(x);
820  }
821 
822 
824 static inline FXfloat atan2(FXfloat y,FXfloat x){
825  return ::atan2f(y,x);
826  }
827 
829 static inline FXdouble atan2(FXdouble y,FXdouble x){
830  return ::atan2(y,x);
831  }
832 
833 
835 static inline void sincos(FXfloat x,FXfloat& s,FXfloat& c){
836 #if defined(NO_SINCOSF)
837  s=Math::sin(x);
838  c=Math::cos(x);
839 #else
840  ::sincosf(x,&s,&c);
841 #endif
842  }
843 
844 
846 static inline void sincos(FXdouble x,FXdouble& s,FXdouble& c){
847 #if defined(NO_SINCOS)
848  s=Math::sin(x);
849  c=Math::cos(x);
850 #else
851  ::sincos(x,&s,&c);
852 #endif
853  }
854 
855 
857 #if defined(NO_SINHF)
858 extern FXAPI FXfloat sinh(FXfloat x);
859 #else
860 static inline FXfloat sinh(FXfloat x){ return ::sinhf(x); }
861 #endif
862 
864 #if defined(NO_SINH)
865 extern FXAPI FXdouble sinh(FXdouble x);
866 #else
867 static inline FXdouble sinh(FXdouble x){ return ::sinh(x); }
868 #endif
869 
870 
872 #if defined(NO_COSHF)
873 extern FXAPI FXfloat cosh(FXfloat x);
874 #else
875 static inline FXfloat cosh(FXfloat x){ return ::coshf(x); }
876 #endif
877 
879 #if defined(NO_COSH)
880 extern FXAPI FXdouble cosh(FXdouble x);
881 #else
882 static inline FXdouble cosh(FXdouble x){ return ::cosh(x); }
883 #endif
884 
885 
887 #if defined(NO_TANHF)
888 extern FXAPI FXfloat tanh(FXfloat x);
889 #else
890 static inline FXfloat tanh(FXfloat x){ return ::tanhf(x); }
891 #endif
892 
894 #if defined(NO_TANH)
895 extern FXAPI FXdouble tanh(FXdouble x);
896 #else
897 static inline FXdouble tanh(FXdouble x){ return ::tanh(x); }
898 #endif
899 
900 
902 #if defined(NO_ASINHF)
903 extern FXAPI FXfloat asinh(FXfloat x);
904 #else
905 static inline FXfloat asinh(FXfloat x){ return ::asinhf(x); }
906 #endif
907 
909 #if defined(NO_ASINH)
910 extern FXAPI FXdouble asinh(FXdouble x);
911 #else
912 static inline FXdouble asinh(FXdouble x){ return ::asinh(x); }
913 #endif
914 
915 
917 #if defined(NO_ACOSHF)
918 extern FXAPI FXfloat acosh(FXfloat x);
919 #else
920 static inline FXfloat acosh(FXfloat x){ return ::acoshf(x); }
921 #endif
922 
924 #if defined(NO_ACOSH)
925 extern FXAPI FXdouble acosh(FXdouble x);
926 #else
927 static inline FXdouble acosh(FXdouble x){ return ::acosh(x); }
928 #endif
929 
930 
932 #if defined(NO_ATANHF)
933 extern FXAPI FXfloat atanh(FXfloat x);
934 #else
935 static inline FXfloat atanh(FXfloat x){ return ::atanhf(x); }
936 #endif
937 
939 #if defined(NO_ATANH)
940 extern FXAPI FXdouble atanh(FXdouble x);
941 #else
942 static inline FXdouble atanh(FXdouble x){ return ::atanh(x); }
943 #endif
944 
945 
947 static inline FXfloat sqrt(FXfloat x){
948  return ::sqrtf(x);
949  }
950 
952 static inline FXdouble sqrt(FXdouble x){
953  return ::sqrt(x);
954  }
955 
956 
958 static inline FXfloat safesqrt(FXfloat x){
959  return Math::sqrt(Math::fmax(x,0.0f));
960  }
961 
963 static inline FXdouble safesqrt(FXdouble x){
964  return Math::sqrt(Math::fmax(x,0.0));
965  }
966 
967 
969 static inline FXfloat cbrt(FXfloat x){
970 #if defined(NO_CBRTF)
971  return ::powf(x,0.333333333333333333333333333333f);
972 #else
973  return ::cbrtf(x);
974 #endif
975  }
976 
978 static inline FXdouble cbrt(FXdouble x){
979 #if defined(NO_CBRT)
980  return ::pow(x,0.333333333333333333333333333333);
981 #else
982  return ::cbrt(x);
983 #endif
984  }
985 
986 
988 static inline FXfloat sqr(FXfloat x){
989  return x*x;
990  }
991 
993 static inline FXdouble sqr(FXdouble x){
994  return x*x;
995  }
996 
997 
999 static inline FXfloat cub(FXfloat x){
1000  return x*x*x;
1001  }
1002 
1004 static inline FXdouble cub(FXdouble x){
1005  return x*x*x;
1006  }
1007 
1008 
1010 static inline FXfloat rsqrt(FXfloat x){
1011  return 1.0f/Math::sqrt(x);
1012  }
1013 
1014 
1016 static inline FXdouble rsqrt(FXdouble x){
1017  return 1.0/Math::sqrt(x);
1018  }
1019 
1020 
1022 static inline FXfloat recip(FXfloat x){
1023  return 1.0f/x;
1024  }
1025 
1026 
1028 static inline FXdouble recip(FXdouble x){
1029  return 1.0/x;
1030  }
1031 
1032 
1034 static inline FXfloat hypot(FXfloat x,FXfloat y){
1035 #if defined(NO_HYPOTF)
1036  return Math::sqrt(Math::sqr(x)+Math::sqr(y));
1037 #else
1038  return ::hypotf(x,y);
1039 #endif
1040  }
1041 
1043 static inline FXdouble hypot(FXdouble x,FXdouble y){
1044 #if defined(NO_HYPOT)
1045  return Math::sqrt(Math::sqr(x)+Math::sqr(y));
1046 #else
1047  return ::hypot(x,y);
1048 #endif
1049  }
1050 
1051 
1053 static inline FXfloat lerp(FXfloat u,FXfloat v,FXfloat f){
1054  return (v-u)*f+u;
1055  }
1056 
1057 
1059 static inline FXdouble lerp(FXdouble u,FXdouble v,FXdouble f){
1060  return (v-u)*f+u;
1061  }
1062 
1063 
1065 static inline FXfloat smoothstep(FXfloat f){
1066  return (3.0f-2.0f*f)*f*f;
1067  }
1068 
1070 static inline FXdouble smoothstep(FXdouble f){
1071  return (3.0-2.0*f)*f*f;
1072  }
1073 
1074 
1076 static inline FXfloat exp(FXfloat x){
1077  return ::expf(x);
1078  }
1079 
1081 static inline FXdouble exp(FXdouble x){
1082  return ::exp(x);
1083  }
1084 
1085 
1087 static inline FXfloat expm1(FXfloat x){
1088 #if defined(NO_EXPM1F)
1089  return ::expf(x)-1.0f;
1090 #else
1091  return ::expm1f(x);
1092 #endif
1093  }
1094 
1096 static inline FXdouble expm1(FXdouble x){
1097 #if defined(NO_EXPM1)
1098  return ::exp(x)-1.0;
1099 #else
1100  return ::expm1(x);
1101 #endif
1102  }
1103 
1104 
1106 static inline FXfloat pow(FXfloat x,FXfloat y){
1107  return ::powf(x,y);
1108  }
1109 
1111 static inline FXdouble pow(FXdouble x,FXdouble y){
1112  return ::pow(x,y);
1113  }
1114 
1115 
1117 static inline FXfloat exp2(FXfloat x){
1118 #if defined(NO_EXP2F)
1119  return Math::pow(2.0f,x);
1120 #else
1121  return ::exp2f(x);
1122 #endif
1123  }
1124 
1125 
1127 static inline FXdouble exp2(FXdouble x){
1128 #if defined(NO_EXP2)
1129  return Math::pow(2.0,x);
1130 #else
1131  return ::exp2(x);
1132 #endif
1133  }
1134 
1135 
1137 static inline FXfloat exp10(FXfloat x){
1138 #if defined(NO_EXP10F)
1139  return Math::pow(10.0f,x);
1140 #else
1141  return ::exp10f(x);
1142 #endif
1143  }
1144 
1145 
1147 static inline FXdouble exp10(FXdouble x){
1148 #if defined(NO_EXP10)
1149  return Math::pow(10.0,x);
1150 #else
1151  return ::exp10(x);
1152 #endif
1153  }
1154 
1155 
1157 static inline FXfloat pow10(FXfloat x){
1158  return Math::exp10(x);
1159  }
1160 
1162 static inline FXdouble pow10(FXdouble x){
1163  return Math::exp10(x);
1164  }
1165 
1166 
1168 extern FXAPI FXdouble pow10i(FXint ex);
1169 
1170 
1172 extern FXAPI FXfloat powi(FXfloat base,FXint ex);
1173 
1174 
1176 extern FXAPI FXdouble powi(FXdouble base,FXint ex);
1177 
1178 
1180 static inline FXfloat log(FXfloat x){
1181  return ::logf(x);
1182  }
1183 
1185 static inline FXdouble log(FXdouble x){
1186  return ::log(x);
1187  }
1188 
1189 
1191 static inline FXfloat log1p(FXfloat x){
1192 #if defined(NO_LOG1PF)
1193  return Math::log(1.0f+x);
1194 #else
1195  return ::log1pf(x);
1196 #endif
1197  }
1198 
1199 
1201 static inline FXdouble log1p(FXdouble x){
1202 #if defined(NO_LOG1P)
1203  return Math::log(1.0+x);
1204 #else
1205  return ::log1p(x);
1206 #endif
1207  }
1208 
1209 
1211 static inline FXfloat log2(FXfloat x){
1212 #if defined(NO_LOG2F)
1213  return Math::log(x)*1.442695040888963407359924681001892137f;
1214 #else
1215  return ::log2f(x);
1216 #endif
1217  }
1218 
1219 
1221 static inline FXdouble log2(FXdouble x){
1222 #if defined(NO_LOG2)
1223  return Math::log(x)*1.442695040888963407359924681001892137;
1224 #else
1225  return ::log2(x);
1226 #endif
1227  }
1228 
1229 
1231 static inline FXfloat log10(FXfloat x){
1232  return ::log10f(x);
1233  }
1234 
1236 static inline FXdouble log10(FXdouble x){
1237  return ::log10(x);
1238  }
1239 
1240 
1242 extern FXAPI FXfloat erf(FXfloat x);
1243 
1245 extern FXAPI FXdouble erf(FXdouble x);
1246 
1247 
1249 extern FXAPI FXfloat erfc(FXfloat x);
1250 
1252 extern FXAPI FXdouble erfc(FXdouble x);
1253 
1254 
1256 extern FXAPI FXfloat inverf(FXfloat x);
1257 
1259 extern FXAPI FXdouble inverf(FXdouble x);
1260 
1261 
1263 extern FXAPI FXfloat inverfc(FXfloat x);
1264 
1266 extern FXAPI FXdouble inverfc(FXdouble x);
1267 
1268 
1269 }
1270 
1271 }
1272 
1273 #endif
Definition: FX4Splitter.h:28

Copyright © 1997-2022 Jeroen van der Zijp