minilogue xd SDK  v1.1-0
float_math.h
Go to the documentation of this file.
1 /*
2  BSD 3-Clause License
3 
4  Copyright (c) 2018, KORG INC.
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12 
13  * Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17  * Neither the name of the copyright holder nor the names of its
18  contributors may be used to endorse or promote products derived from
19  this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 //*/
33 
47 #ifndef __float_math_h
48 #define __float_math_h
49 
50 #include <math.h>
51 #include <stdint.h>
52 
53 /*===========================================================================*/
54 /* Constants. */
55 /*===========================================================================*/
56 
62 #ifndef M_E
63 #define M_E 2.718281828459045f
64 #endif
65 
66 #ifndef M_LOG2E
67 #define M_LOG2E 1.44269504088896f
68 #endif
69 
70 #ifndef M_LOG10E
71 #define M_LOG10E 0.4342944819032518f
72 #endif
73 
74 #ifndef M_LN2
75 #define M_LN2 0.6931471805599453094f
76 #endif
77 
78 #ifndef M_LN10
79 #define M_LN10 2.30258509299404568402f
80 #endif
81 
82 #ifndef M_PI
83 #define M_PI 3.141592653589793f
84 #endif
85 
86 #ifndef M_TWOPI
87 #define M_TWOPI 6.283185307179586f
88 #endif
89 
90 #ifndef M_PI_2
91 #define M_PI_2 1.5707963267948966f
92 #endif
93 
94 #ifndef M_PI_4
95 #define M_PI_4 0.7853981633974483f
96 #endif
97 
98 #ifndef M_1_PI
99 #define M_1_PI 0.3183098861837907f
100 #endif
101 
102 #ifndef M_2_PI
103 #define M_2_PI 0.6366197723675814f
104 #endif
105 
106 #ifndef M_4_PI
107 #define M_4_PI 1.2732395447351627f
108 #endif
109 
110 #ifndef M_1_TWOPI
111 #define M_1_TWOPI 0.15915494309189534f
112 #endif
113 
114 #ifndef M_2_SQRTPI
115 #define M_2_SQRTPI 1.1283791670955126f
116 #endif
117 
118 #ifndef M_4_PI2
119 #define M_4_PI2 0.40528473456935109f
120 #endif
121 
122 #ifndef M_SQRT2
123 #define M_SQRT2 1.41421356237309504880f
124 #endif
125 
126 #ifndef M_1_SQRT2
127 #define M_1_SQRT2 0.7071067811865475f
128 #endif
129 
132 /*===========================================================================*/
133 /* Macros. */
134 /*===========================================================================*/
135 
141 #define F32_FRAC_MASK ((1L<<23)-1)
142 #define F32_EXP_MASK (((1L<<9)-1)<<23)
143 #define F32_SIGN_MASK (0x80000000)
144 
145 //Note: need to pass an integer representation
146 #define f32_frac_bits(f) ((f) & F32_FRAC_MASK)
147 #define f32_exp_bits(f) ((f) & F32_EXP_MASK)
148 #define f32_sign_bit(f) ((f) & F32_SIGN_MASK)
149 
152 /*===========================================================================*/
153 /* Types. */
154 /*===========================================================================*/
155 
161 typedef union {
162  float f;
163  uint32_t i;
164 } f32_t;
165 
166 typedef struct {
167  float a;
168  float b;
169 } f32pair_t;
170 
173 static inline __attribute__((optimize("Ofast"),always_inline))
174 f32pair_t f32pair(const float a, const float b) {
175  return (f32pair_t){a, b};
176 }
177 
180 /*===========================================================================*/
181 /* Operations. */
182 /*===========================================================================*/
183 
191 static inline __attribute__((optimize("Ofast"),always_inline))
192 float fsel(const float a, const float b, const float c) {
193  return (a >= 0) ? b : c;
194 }
195 
198 static inline __attribute__((optimize("Ofast"),always_inline))
199 uint8_t fselb(const float a) {
200  return (a >= 0) ? 1 : 0;
201 }
202 
205 static inline __attribute__((always_inline))
206 uint8_t float_is_neg(const f32_t f) {
207  return (f.i >> 31) != 0;
208 }
209 
212 static inline __attribute__((always_inline))
213 int32_t float_mantissa(f32_t f) {
214  return f.i & ((1 << 23) - 1);
215 }
216 
219 static inline __attribute__((always_inline))
220 int32_t float_exponent(f32_t f) {
221  return (f.i >> 23) & 0xFF;
222 }
223 
226 static inline __attribute__((optimize("Ofast"),always_inline))
228  return (f32pair_t){p0.a + p1.a, p0.b + p1.b};
229 }
230 
233 static inline __attribute__((optimize("Ofast"),always_inline))
235  return (f32pair_t){p0.a - p1.a, p0.b - p1.b};
236 }
237 
240 static inline __attribute__((optimize("Ofast"),always_inline))
241 f32pair_t f32pair_addscal(const f32pair_t p, const float scl) {
242  return (f32pair_t){p.a + scl, p.b + scl};
243 }
244 
247 static inline __attribute__((optimize("Ofast"),always_inline))
249  return (f32pair_t){p0.a * p1.a, p0.b * p1.b};
250 }
251 
254 static inline __attribute__((optimize("Ofast"),always_inline))
255 f32pair_t f32pair_mulscal(const f32pair_t p, const float scl) {
256  return (f32pair_t){p.a * scl, p.b * scl};
257 }
258 
261 static inline __attribute__((optimize("Ofast"),always_inline))
262 f32pair_t f32pair_linint(const float fr, const f32pair_t p0, const f32pair_t p1) {
263  const float frinv = 1.f - fr;
264  return (f32pair_t){ frinv * p0.a + fr * p1.a, frinv * p0.b + fr * p1.b };
265 }
266 
269 static inline __attribute__((optimize("Ofast"),always_inline))
270 float si_copysignf(const float x, const float y)
271 {
272  f32_t xs = {x};
273  f32_t ys = {y};
274 
275  xs.i &= 0x7fffffff;
276  xs.i |= ys.i & 0x80000000;
277 
278  return xs.f;
279 }
280 
283 static inline __attribute__((optimize("Ofast"),always_inline))
284 float si_fabsf(float x)
285 {
286  f32_t xs = {x};
287  xs.i &= 0x7fffffff;
288  return xs.f;
289 }
290 
293 static inline __attribute__((optimize("Ofast"),always_inline))
294 float si_floorf(float x)
295 {
296  return (float)((uint32_t)x);
297 }
298 
301 static inline __attribute__((optimize("Ofast"),always_inline))
302 float si_ceilf(float x)
303 {
304  return (float)((uint32_t)x + 1);
305 }
306 
309 static inline __attribute__((optimize("Ofast"),always_inline))
310 float si_roundf(float x)
311 {
312  return (float)((int32_t)(x + si_copysignf(0.5f,x)));
313 }
314 
315 static inline __attribute__((optimize("Ofast"), always_inline))
316 float clampfsel(const float min, float x, const float max)
317 {
318  x = fsel(x - min, x, min);
319  return fsel(x - max, max, x);
320 }
321 
322 static inline __attribute__((optimize("Ofast"), always_inline))
323 float clampminfsel(const float min, const float x)
324 {
325  return fsel(x - min, x, min);
326 }
327 
328 static inline __attribute__((optimize("Ofast"), always_inline))
329 float clampmaxfsel(const float x, const float max)
330 {
331  return fsel(x - max, max, x);
332 }
333 
334 #if defined(FLOAT_CLIP_NOFSEL)
335 
338 static inline __attribute__((optimize("Ofast"), always_inline))
339 float clipmaxf(const float x, const float m)
340 { return (((x)>=m)?m:(x)); }
341 
344 static inline __attribute__((optimize("Ofast"), always_inline))
345 float clipminf(const float m, const float x)
346 { return (((x)<=m)?m:(x)); }
347 
350 static inline __attribute__((optimize("Ofast"), always_inline))
351 float clipminmaxf(const float min, const float x, const float max)
352 { return (((x)>=max)?max:((x)<=min)?min:(x)); }
353 
356 static inline __attribute__((optimize("Ofast"), always_inline))
357 float clip0f(const float x)
358 { return (((x)<0.f)?0.f:(x)); }
359 
362 static inline __attribute__((optimize("Ofast"), always_inline))
363 float clip1f(const float x)
364 { return (((x)>1.f)?1.f:(x)); }
365 
368 static inline __attribute__((optimize("Ofast"), always_inline))
369 float clip01f(const float x)
370 { return (((x)>1.f)?1.f:((x)<0.f)?0.f:(x)); }
371 
374 static inline __attribute__((optimize("Ofast"), always_inline))
375 float clipm1f(const float x)
376 { return (((x)<-1.f)?-1.f:(x)); }
377 
380 static inline __attribute__((optimize("Ofast"), always_inline))
381 float clip1m1f(const float x)
382 { return (((x)>1.f)?1.f:((x)<-1.f)?-1.f:(x)); }
383 
384 #else
385 
388 static inline __attribute__((optimize("Ofast"), always_inline))
389 float clipmaxf(const float x, const float m)
390 { return clampmaxfsel(x, m); }
391 
394 static inline __attribute__((optimize("Ofast"), always_inline))
395 float clipminf(const float m, const float x)
396 { return clampminfsel(m, x); }
397 
400 static inline __attribute__((optimize("Ofast"), always_inline))
401 float clipminmaxf(const float min, const float x, const float max)
402 { return clampfsel(min, x, max); }
403 
406 static inline __attribute__((optimize("Ofast"), always_inline))
407 float clip0f(const float x)
408 { return clampminfsel(0, x); }
409 
412 static inline __attribute__((optimize("Ofast"), always_inline))
413 float clip1f(const float x)
414 { return clampmaxfsel(x, 1); }
415 
418 static inline __attribute__((optimize("Ofast"), always_inline))
419 float clip01f(const float x)
420 { return clampfsel(0, x, 1); }
421 
424 static inline __attribute__((optimize("Ofast"), always_inline))
425 float clipm1f(const float x)
426 { return clampminfsel(-1, x); }
427 
430 static inline __attribute__((optimize("Ofast"), always_inline))
431 float clip1m1f(const float x)
432 { return clampfsel(-1, x, 1); }
433 
434 #endif
435 
438 /*===========================================================================*/
439 /* Useful Functions. */
440 /*===========================================================================*/
441 
448 /*=====================================================================*
449  * *
450  * fastersinf, fastercosf, fastersinfullf, fastercosfullf, *
451  * fastertanfullf, fasterpow2f, fasterexpf, fasterlog2f, *
452  * and fasterpowf adapted from FastFloat code with the following *
453  * disclaimer: *
454  * *
455  * *
456  * Copyright (C) 2011 Paul Mineiro *
457  * All rights reserved. *
458  * *
459  * Redistribution and use in source and binary forms, with *
460  * or without modification, are permitted provided that the *
461  * following conditions are met: *
462  * *
463  * * Redistributions of source code must retain the *
464  * above copyright notice, this list of conditions and *
465  * the following disclaimer. *
466  * *
467  * * Redistributions in binary form must reproduce the *
468  * above copyright notice, this list of conditions and *
469  * the following disclaimer in the documentation and/or *
470  * other materials provided with the distribution. *
471  * *
472  * * Neither the name of Paul Mineiro nor the names *
473  * of other contributors may be used to endorse or promote *
474  * products derived from this software without specific *
475  * prior written permission. *
476  * *
477  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
478  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
479  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
480  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
481  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER *
482  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
483  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
484  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *
485  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
486  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
487  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
488  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
489  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
490  * POSSIBILITY OF SUCH DAMAGE. *
491  * *
492  * Contact: Paul Mineiro <paul@mineiro.com> *
493  *=====================================================================*/
494 
498 static inline __attribute__((optimize("Ofast"), always_inline))
499 float fastsinf(float x) {
500  static const float q = 0.78444488374548933f;
501  union { float f; uint32_t i; } p = { 0.20363937680730309f };
502  union { float f; uint32_t i; } r = { 0.015124940802184233f };
503  union { float f; uint32_t i; } s = { -0.0032225901625579573f };
504 
505  union { float f; uint32_t i; } vx = { x };
506  uint32_t sign = vx.i & 0x80000000;
507  vx.i = vx.i & 0x7FFFFFFF;
508 
509  float qpprox = M_4_PI * x - M_4_PI2 * x * vx.f;
510  float qpproxsq = qpprox * qpprox;
511 
512  p.i |= sign;
513  r.i |= sign;
514  s.i ^= sign;
515 
516  return q * qpprox + qpproxsq * (p.f + qpproxsq * (r.f + qpproxsq * s.f));
517 }
518 
523 static inline __attribute__((optimize("Ofast"), always_inline))
524 float fastersinf(float x) {
525  static const float q = 0.77633023248007499f;
526  union { float f; uint32_t i; } p = { 0.22308510060189463f };
527  union { float f; uint32_t i; } vx = { x };
528  const uint32_t sign = vx.i & 0x80000000;
529  vx.i &= 0x7FFFFFFF;
530  const float qpprox = M_4_PI * x - M_4_PI2 * x * vx.f;
531  p.i |= sign;
532  return qpprox * (q + p.f * qpprox);
533 }
534 
538 static inline __attribute__((optimize("Ofast"), always_inline))
539 float fastsinfullf(float x) {
540  const int32_t k = (int32_t)(x * M_1_TWOPI);
541  const float half = (x < 0) ? -0.5f : 0.5f;
542  return fastsinf((half + k) * M_TWOPI - x);
543 }
544 
548 static inline __attribute__((optimize("Ofast"), always_inline))
549 float fastersinfullf(float x) {
550  const int32_t k = (int32_t)(x * M_1_TWOPI);
551  const float half = (x < 0) ? -0.5f : 0.5f;
552  return fastersinf((half + k) * M_TWOPI - x);
553 }
554 
558 static inline __attribute__((optimize("Ofast"), always_inline))
559 float fastcosf(float x) {
560  const float halfpiminustwopi = -4.7123889803846899f;
561  float offset = (x > M_PI_2) ? halfpiminustwopi : M_PI_2;
562  return fastsinf(x + offset);
563 }
564 
568 static inline __attribute__((optimize("Ofast"), always_inline))
569 float fastercosf(float x) {
570  static const float p = 0.54641335845679634f;
571  union { float f; uint32_t i; } vx = { x };
572  vx.i &= 0x7FFFFFFF;
573  const float qpprox = 1.0f - M_2_PI * vx.f;
574  return qpprox + p * qpprox * (1.0f - qpprox * qpprox);
575 }
576 
581 static inline __attribute__((optimize("Ofast"), always_inline))
582 float fastcosfullf(float x) {
583  return fastersinfullf(x + M_PI_2);
584 }
585 
589 static inline __attribute__((optimize("Ofast"), always_inline))
590 float fastercosfullf(float x) {
591  return fastersinfullf(x + M_PI_2);
592 }
593 
597 static inline __attribute__((optimize("Ofast"), always_inline))
598 float fasttanf(float x) {
599  return fastsinf(x) / fastsinf(x + M_PI_2);
600 }
601 
605 static inline __attribute__((optimize("Ofast"), always_inline))
606 float fastertanf(float x) {
607  return fastcosf(x) / fastercosf(x);
608 }
609 
614 static inline __attribute__((optimize("Ofast"), always_inline))
615 float fasttanfullf(float x) {
616  const int32_t k = (int32_t)(x * M_1_TWOPI);
617  const float half = (x < 0) ? -0.5f : 0.5f;
618  const float xnew = x - (half + k) * M_TWOPI;
619  return fastsinf(xnew)/fastcosf(xnew);
620 }
621 
625 static inline __attribute__((optimize("Ofast"), always_inline))
626 float fastertanfullf(float x) {
627  const int32_t k = (int32_t)(x * M_1_TWOPI);
628  const float half = (x < 0) ? -0.5f : 0.5f;
629  const float xnew = x - (half + k) * M_TWOPI;
630  return fastersinf(xnew)/fastercosf(xnew);
631 }
632 
636 static inline __attribute__((optimize("Ofast"), always_inline))
637 float fastlog2f(float x) {
638  union { float f; uint32_t i; } vx = { x };
639  union { uint32_t i; float f; } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };
640  float y = vx.i;
641  y *= 1.1920928955078125e-7f;
642 
643  return y - 124.22551499f
644  - 1.498030302f * mx.f
645  - 1.72587999f / (0.3520887068f + mx.f);
646 }
647 
651 static inline __attribute__((optimize("Ofast"), always_inline))
652 float fasterlog2f(float x) {
653  union { float f; uint32_t i; } vx = { x };
654  float y = (float)(vx.i);
655  y *= 1.1920928955078125e-7f;
656  return y - 126.94269504f;
657 }
658 
662 static inline __attribute__((optimize("Ofast"), always_inline))
663 float fastlogf(float x) {
664  return 0.69314718f * fastlog2f(x);
665 }
666 
670 static inline __attribute__((optimize("Ofast"), always_inline))
671 float fasterlogf(float x) {
672  return 0.69314718f * fasterlog2f(x);
673 }
674 
678 static inline __attribute__((optimize("Ofast"), always_inline))
679 float fastpow2f(float p) {
680  float clipp = (p < -126) ? -126.0f : p;
681  int w = clipp;
682  float z = clipp - w + 1.f;
683  union { uint32_t i; float f; } v = { (uint32_t) ( (1 << 23) *
684  (clipp + 121.2740575f + 27.7280233f / (4.84252568f - z) - 1.49012907f * z)
685  ) };
686 
687  return v.f;
688 }
689 
693 static inline __attribute__((optimize("Ofast"), always_inline))
694 float fasterpow2f(float p) {
695  float clipp = (p < -126) ? -126.0f : p;
696  union { uint32_t i; float f; } v = { (uint32_t)( (1 << 23) * (clipp + 126.94269504f) ) };
697  return v.f;
698 }
699 
704 static inline __attribute__((optimize("Ofast"), always_inline))
705 float fastpowf(float x, float p) {
706  return fastpow2f(p * fastlog2f(x));
707 }
708 
712 static inline __attribute__((optimize("Ofast"), always_inline))
713 float fasterpowf(float x, float p) {
714  return fasterpow2f(p * fasterlog2f(x));
715 }
716 
720 static inline __attribute__((optimize("Ofast"), always_inline))
721 float fastexpf(float p) {
722  return fastpow2f(1.442695040f * p);
723 }
724 
728 static inline __attribute__((optimize("Ofast"), always_inline))
729 float fasterexpf(float p) {
730  return fasterpow2f(1.442695040f * p);
731 }
732 
733 /*= End of FastFloat derived code =====================================*/
734 
738 static inline __attribute__((optimize("Ofast"), always_inline))
739 float fasteratan2f(float y, float x) {
740  const float coeff_1 = M_PI_4;
741  const float coeff_2 = 3 * coeff_1;
742  float abs_y = si_fabsf(y) + 1e-10f; // kludge to prevent 0/0 condition
743  float r, angle;
744  if (x >= 0) {
745  r = (x - abs_y) / (x + abs_y);
746  angle = coeff_1 - coeff_1 * r;
747  }
748  else {
749  r = (x + abs_y) / (abs_y - x);
750  angle = coeff_2 - coeff_1 * r;
751  }
752  return (y < 0) ? -angle : angle; // negate if in quad III or IV
753 }
754 
758 static inline __attribute__((optimize("Ofast"), always_inline))
759 float fastertanhf(float x) {
760  return (-0.67436811832e-5f +
761  (0.2468149110712040f +
762  (0.583691066395175e-1f + 0.3357335044280075e-1f * x) * x) * x) /
763  (0.2464845986383725f +
764  (0.609347197060491e-1f +
765  (0.1086202599228572f + 0.2874707922475963e-1f * x) * x) * x);
766 }
767 
770 /*===========================================================================*/
771 /* Useful Conversions. */
772 /*===========================================================================*/
773 
783 static inline __attribute__((optimize("Ofast"), always_inline))
784 float ampdbf(const float amp) {
785  return (amp < 0.f) ? -999.f : 20.f*log10f(amp);
786 }
787 
790 static inline __attribute__((optimize("Ofast"), always_inline))
791 float fasterampdbf(const float amp) {
792  return 20.f*fasterlog2f(amp)/fasterlog2f(10);
793 }
794 
797 static inline __attribute__((optimize("Ofast"), always_inline))
798 float dbampf(const float db) {
799  return powf(10.f,0.05f*db);
800 }
801 
804 static inline __attribute__((optimize("Ofast"), always_inline))
805 float fasterdbampf(const float db) {
806  return 20.f*fasterpowf(10.f, 0.05f*db);
807 }
808 
811 /*===========================================================================*/
812 /* Interpolation. */
813 /*===========================================================================*/
814 
823 static inline __attribute__((optimize("Ofast"), always_inline))
824 float linintf(const float fr, const float x0, const float x1) {
825  return x0 + fr * (x1 - x0);
826 }
827 
830 static inline __attribute__((optimize("Ofast"), always_inline))
831 float cosintf(const float fr, const float x0, const float x1) {
832  const float tmp = (1.f - fastercosfullf(fr * M_PI)) * 0.5f;
833  return x0 + tmp * (x1 - x0);
834 }
835 
838 #endif // __float_math_h
839 
si_ceilf
static float si_ceilf(float x)
Ceiling function.
Definition: float_math.h:302
f32pair_linint
static f32pair_t f32pair_linint(const float fr, const f32pair_t p0, const f32pair_t p1)
Pair-wise linear interpolation.
Definition: float_math.h:262
fastersinfullf
static float fastersinfullf(float x)
"Faster" sine approximation, valid on full x domain
Definition: float_math.h:549
fasterexpf
static float fasterexpf(float p)
"Faster" exponential approximation, valid for x in [ ~ -87, ...
Definition: float_math.h:729
fastsinf
static float fastsinf(float x)
"Fast" sine approximation, valid for x in [-M_PI, M_PI]
Definition: float_math.h:499
fasttanfullf
static float fasttanfullf(float x)
"Fast" tangent approximation, valid on full x domain, except where tangent diverges.
Definition: float_math.h:615
f32pair_mul
static f32pair_t f32pair_mul(const f32pair_t p0, const f32pair_t p1)
Pair-wise product.
Definition: float_math.h:248
f32pair_sub
static f32pair_t f32pair_sub(const f32pair_t p0, const f32pair_t p1)
Pair-wise subtraction.
Definition: float_math.h:234
fastexpf
static float fastexpf(float p)
"Fast" exponential approximation, valid for x in [ ~ -87, ...
Definition: float_math.h:721
float_mantissa
static int32_t float_mantissa(f32_t f)
Obtain mantissa.
Definition: float_math.h:213
f32pair_add
static f32pair_t f32pair_add(const f32pair_t p0, const f32pair_t p1)
Pair-wise addition.
Definition: float_math.h:227
fasteratan2f
static float fasteratan2f(float y, float x)
atan2 approximation
Definition: float_math.h:739
clipm1f
static float clipm1f(const float x)
Clip lower bound of x to -1.f (inclusive)
Definition: float_math.h:425
dbampf
static float dbampf(const float db)
dB to ampltitude
Definition: float_math.h:798
fastercosf
static float fastercosf(float x)
"Faster" cosine approximation, valid for x in [-M_PI, M_PI]
Definition: float_math.h:569
clipminmaxf
static float clipminmaxf(const float min, const float x, const float max)
Clip x to min and max (inclusive)
Definition: float_math.h:401
si_roundf
static float si_roundf(float x)
Round to nearest integer.
Definition: float_math.h:310
clipmaxf
static float clipmaxf(const float x, const float m)
Clip upper bound of x to m (inclusive)
Definition: float_math.h:389
fastertanf
static float fastertanf(float x)
"Faster" tangent approximation, valid for x in [-M_PI_2, M_PI_2]
Definition: float_math.h:606
fastsinfullf
static float fastsinfullf(float x)
"Fast" sine approximation, valid on full x domain
Definition: float_math.h:539
clip0f
static float clip0f(const float x)
Clip lower bound of x to 0.f (inclusive)
Definition: float_math.h:407
float_is_neg
static uint8_t float_is_neg(const f32_t f)
Sign bit check.
Definition: float_math.h:206
fselb
static uint8_t fselb(const float a)
FSEL boolean construct.
Definition: float_math.h:199
clipminf
static float clipminf(const float m, const float x)
Clip lower bound of x to m (inclusive)
Definition: float_math.h:395
fasterampdbf
static float fasterampdbf(const float amp)
"Faster" Amplitude to dB
Definition: float_math.h:791
si_copysignf
static float si_copysignf(const float x, const float y)
Return x with sign of y applied.
Definition: float_math.h:270
fastcosfullf
static float fastcosfullf(float x)
"Fast" cosine approximation, valid on full x domain
Definition: float_math.h:582
fastercosfullf
static float fastercosfullf(float x)
"Faster" cosine approximation, valid on full x domain
Definition: float_math.h:590
f32pair_addscal
static f32pair_t f32pair_addscal(const f32pair_t p, const float scl)
Pair-wise scalar addition.
Definition: float_math.h:241
si_floorf
static float si_floorf(float x)
Floor function.
Definition: float_math.h:294
fasterlogf
static float fasterlogf(float x)
"Fast" natural logarithm approximation, valid for positive x as precision allows.
Definition: float_math.h:671
fasterpow2f
static float fasterpow2f(float p)
"Faster" power of 2 approximation, valid for x in [ -126, ...
Definition: float_math.h:694
fastertanhf
static float fastertanhf(float x)
Hyperbolic tangent approximation.
Definition: float_math.h:759
fastpow2f
static float fastpow2f(float p)
"Fast" power of 2 approximation, valid for x in [ -126, ...
Definition: float_math.h:679
fasterdbampf
static float fasterdbampf(const float db)
"Faster" dB to ampltitude
Definition: float_math.h:805
f32pair
static f32pair_t f32pair(const float a, const float b)
Make a float pair.
Definition: float_math.h:174
fastlog2f
static float fastlog2f(float x)
"Fast" log base 2 approximation, valid for positive x as precision allows.
Definition: float_math.h:637
fastpowf
static float fastpowf(float x, float p)
"Fast" x to the power of p approximation
Definition: float_math.h:705
fasterpowf
static float fasterpowf(float x, float p)
"Faster" x to the power of p approximation
Definition: float_math.h:713
clip01f
static float clip01f(const float x)
Clip x to [0.f, 1.f] (inclusive)
Definition: float_math.h:419
fsel
static float fsel(const float a, const float b, const float c)
FSEL construct.
Definition: float_math.h:192
fastcosf
static float fastcosf(float x)
"Fast" cosine approximation, valid for x in [-M_PI, M_PI]
Definition: float_math.h:559
clip1f
static float clip1f(const float x)
Clip upper bound of x to 1.f (inclusive)
Definition: float_math.h:413
ampdbf
static float ampdbf(const float amp)
Amplitude to dB.
Definition: float_math.h:784
float_exponent
static int32_t float_exponent(f32_t f)
Obtain exponent.
Definition: float_math.h:220
fastertanfullf
static float fastertanfullf(float x)
"Faster" tangent approximation, valid on full x domain, except where tangent diverges.
Definition: float_math.h:626
clip1m1f
static float clip1m1f(const float x)
Clip x to [-1.f, 1.f] (inclusive)
Definition: float_math.h:431
f32pair_t
Definition: float_math.h:166
fastersinf
static float fastersinf(float x)
"Faster" sine approximation, valid for x in [-M_PI, M_PI]
Definition: float_math.h:524
f32_t
Definition: float_math.h:161
fasttanf
static float fasttanf(float x)
"Fast" tangent approximation, valid for x in [-M_PI_2, M_PI_2]
Definition: float_math.h:598
linintf
static float linintf(const float fr, const float x0, const float x1)
Linear interpolation.
Definition: float_math.h:824
si_fabsf
static float si_fabsf(float x)
Absolute value.
Definition: float_math.h:284
cosintf
static float cosintf(const float fr, const float x0, const float x1)
Cosine interpolation.
Definition: float_math.h:831
fasterlog2f
static float fasterlog2f(float x)
"Faster" log base 2 approximation, valid for positive x as precision allows.
Definition: float_math.h:652
fastlogf
static float fastlogf(float x)
"Fast" natural logarithm approximation, valid for positive x as precision allows.
Definition: float_math.h:663
f32pair_mulscal
static f32pair_t f32pair_mulscal(const f32pair_t p, const float scl)
Pair-wise scalar product.
Definition: float_math.h:255