Irrlicht 3D Engine
irrMath.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __IRR_MATH_H_INCLUDED__
6 #define __IRR_MATH_H_INCLUDED__
7 
8 #include "IrrCompileConfig.h"
9 #include "irrTypes.h"
10 #include <math.h>
11 #include <float.h>
12 #include <stdlib.h> // for abs() etc.
13 #include <limits.h> // For INT_MAX / UINT_MAX
14 
15 #if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) || defined (_WIN32_WCE)
16  #define sqrtf(X) (irr::f32)sqrt((irr::f64)(X))
17  #define sinf(X) (irr::f32)sin((irr::f64)(X))
18  #define cosf(X) (irr::f32)cos((irr::f64)(X))
19  #define asinf(X) (irr::f32)asin((irr::f64)(X))
20  #define acosf(X) (irr::f32)acos((irr::f64)(X))
21  #define atan2f(X,Y) (irr::f32)atan2((irr::f64)(X),(irr::f64)(Y))
22  #define ceilf(X) (irr::f32)ceil((irr::f64)(X))
23  #define floorf(X) (irr::f32)floor((irr::f64)(X))
24  #define powf(X,Y) (irr::f32)pow((irr::f64)(X),(irr::f64)(Y))
25  #define fmodf(X,Y) (irr::f32)fmod((irr::f64)(X),(irr::f64)(Y))
26  #define fabsf(X) (irr::f32)fabs((irr::f64)(X))
27  #define logf(X) (irr::f32)log((irr::f64)(X))
28 #endif
29 
30 #ifndef FLT_MAX
31 #define FLT_MAX 3.402823466E+38F
32 #endif
33 
34 #ifndef FLT_MIN
35 #define FLT_MIN 1.17549435e-38F
36 #endif
37 
38 namespace irr
39 {
40 namespace core
41 {
42 
44 
46 
47 #ifdef __IRR_HAS_S64
49 #endif
50  const f32 ROUNDING_ERROR_f32 = 0.000001f;
51  const f64 ROUNDING_ERROR_f64 = 0.00000001;
52 
53 #ifdef PI // make sure we don't collide with a define
54 #undef PI
55 #endif
56  const f32 PI = 3.14159265359f;
58 
60  const f32 RECIPROCAL_PI = 1.0f/PI;
61 
63  const f32 HALF_PI = PI/2.0f;
64 
65 #ifdef PI64 // make sure we don't collide with a define
66 #undef PI64
67 #endif
68  const f64 PI64 = 3.1415926535897932384626433832795028841971693993751;
70 
72  const f64 RECIPROCAL_PI64 = 1.0/PI64;
73 
75  const f32 DEGTORAD = PI / 180.0f;
76 
78  const f32 RADTODEG = 180.0f / PI;
79 
81  const f64 DEGTORAD64 = PI64 / 180.0;
82 
84  const f64 RADTODEG64 = 180.0 / PI64;
85 
87 
90  inline f32 radToDeg(f32 radians)
91  {
92  return RADTODEG * radians;
93  }
94 
96 
99  inline f64 radToDeg(f64 radians)
100  {
101  return RADTODEG64 * radians;
102  }
103 
105 
108  inline f32 degToRad(f32 degrees)
109  {
110  return DEGTORAD * degrees;
111  }
112 
114 
117  inline f64 degToRad(f64 degrees)
118  {
119  return DEGTORAD64 * degrees;
120  }
121 
123  template<class T>
124  inline const T& min_(const T& a, const T& b)
125  {
126  return a < b ? a : b;
127  }
128 
130  template<class T>
131  inline const T& min_(const T& a, const T& b, const T& c)
132  {
133  return a < b ? min_(a, c) : min_(b, c);
134  }
135 
137  template<class T>
138  inline const T& max_(const T& a, const T& b)
139  {
140  return a < b ? b : a;
141  }
142 
144  template<class T>
145  inline const T& max_(const T& a, const T& b, const T& c)
146  {
147  return a < b ? max_(b, c) : max_(a, c);
148  }
149 
151  template<class T>
152  inline T abs_(const T& a)
153  {
154  return a < (T)0 ? -a : a;
155  }
156 
159  template<class T>
160  inline T lerp(const T& a, const T& b, const f32 t)
161  {
162  return (T)(a*(1.f-t)) + (b*t);
163  }
164 
166  template <class T>
167  inline const T clamp (const T& value, const T& low, const T& high)
168  {
169  return min_ (max_(value,low), high);
170  }
171 
173  // Note: We use the same trick as boost and use two template arguments to
174  // avoid ambiguity when swapping objects of an Irrlicht type that has not
175  // it's own swap overload. Otherwise we get conflicts with some compilers
176  // in combination with stl.
177  template <class T1, class T2>
178  inline void swap(T1& a, T2& b)
179  {
180  T1 c(a);
181  a = b;
182  b = c;
183  }
184 
185  template <class T>
186  inline T roundingError();
187 
188  template <>
190  {
191  return ROUNDING_ERROR_f32;
192  }
193 
194  template <>
196  {
197  return ROUNDING_ERROR_f64;
198  }
199 
200  template <>
202  {
203  return ROUNDING_ERROR_S32;
204  }
205 
206  template <>
208  {
209  return ROUNDING_ERROR_S32;
210  }
211 
212 #ifdef __IRR_HAS_S64
213  template <>
215  {
216  return ROUNDING_ERROR_S64;
217  }
218 
219  template <>
221  {
222  return ROUNDING_ERROR_S64;
223  }
224 #endif
225 
226  template <class T>
228  {
229  return 1;
230  }
231 
232  template <>
234  {
235  return 4;
236  }
237 
238  template <>
240  {
241  return 8;
242  }
243 
245  template <class T>
246  inline bool equals(const T a, const T b, const T tolerance = roundingError<T>())
247  {
248  return (a + tolerance >= b) && (a - tolerance <= b);
249  }
250 
251 
254  template <class T>
255  inline bool equalsRelative( const T a, const T b, const T factor = relativeErrorFactor<T>())
256  {
257  //https://eagergames.wordpress.com/2017/04/01/fast-parallel-lines-and-vectors-test/
258 
259  const T maxi = max_( a, b);
260  const T mini = min_( a, b);
261  const T maxMagnitude = max_( maxi, -mini);
262 
263  return (maxMagnitude*factor + maxi) == (maxMagnitude*factor + mini); // MAD Wise
264  }
265 
267  {
268  FloatIntUnion32(float f1 = 0.0f) : f(f1) {}
269  // Portable sign-extraction
270  bool sign() const { return (i >> 31) != 0; }
271 
274  };
275 
277  //\result true when numbers have a ULP <= maxUlpDiff AND have the same sign.
278  inline bool equalsByUlp(f32 a, f32 b, int maxUlpDiff)
279  {
280  // Based on the ideas and code from Bruce Dawson on
281  // http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/
282  // When floats are interpreted as integers the two nearest possible float numbers differ just
283  // by one integer number. Also works the other way round, an integer of 1 interpreted as float
284  // is for example the smallest possible float number.
285 
286  FloatIntUnion32 fa(a);
287  FloatIntUnion32 fb(b);
288 
289  // Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better.
290  if ( fa.sign() != fb.sign() )
291  {
292  // Check for equality to make sure +0==-0
293  if (fa.i == fb.i)
294  return true;
295  return false;
296  }
297 
298  // Find the difference in ULPs.
299  int ulpsDiff = abs_(fa.i- fb.i);
300  if (ulpsDiff <= maxUlpDiff)
301  return true;
302 
303  return false;
304  }
305 
307  inline bool iszero(const f64 a, const f64 tolerance = ROUNDING_ERROR_f64)
308  {
309  return fabs(a) <= tolerance;
310  }
311 
313  inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_f32)
314  {
315  return fabsf(a) <= tolerance;
316  }
317 
319  inline bool isnotzero(const f32 a, const f32 tolerance = ROUNDING_ERROR_f32)
320  {
321  return fabsf(a) > tolerance;
322  }
323 
325  inline bool iszero(const s32 a, const s32 tolerance = 0)
326  {
327  return ( a & 0x7ffffff ) <= tolerance;
328  }
329 
331  inline bool iszero(const u32 a, const u32 tolerance = 0)
332  {
333  return a <= tolerance;
334  }
335 
336 #ifdef __IRR_HAS_S64
337  inline bool iszero(const s64 a, const s64 tolerance = 0)
339  {
340  return abs_(a) <= tolerance;
341  }
342 #endif
343 
344  inline s32 s32_min(s32 a, s32 b)
345  {
346  const s32 mask = (a - b) >> 31;
347  return (a & mask) | (b & ~mask);
348  }
349 
350  inline s32 s32_max(s32 a, s32 b)
351  {
352  const s32 mask = (a - b) >> 31;
353  return (b & mask) | (a & ~mask);
354  }
355 
356  inline s32 s32_clamp (s32 value, s32 low, s32 high)
357  {
358  return s32_min(s32_max(value,low), high);
359  }
360 
361  /*
362  float IEEE-754 bit representation
363 
364  0 0x00000000
365  1.0 0x3f800000
366  0.5 0x3f000000
367  3 0x40400000
368  +inf 0x7f800000
369  -inf 0xff800000
370  +NaN 0x7fc00000 or 0x7ff00000
371  in general: number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits)
372  */
373 
374  typedef union { u32 u; s32 s; f32 f; } inttofloat;
375 
376  #define F32_AS_S32(f) (*((s32 *) &(f)))
377  #define F32_AS_U32(f) (*((u32 *) &(f)))
378  #define F32_AS_U32_POINTER(f) ( ((u32 *) &(f)))
379 
380  #define F32_VALUE_0 0x00000000
381  #define F32_VALUE_1 0x3f800000
382  #define F32_SIGN_BIT 0x80000000U
383  #define F32_EXPON_MANTISSA 0x7FFFFFFFU
384 
387 #ifdef IRRLICHT_FAST_MATH
388  #define IR(x) ((u32&)(x))
389 #else
390  inline u32 IR(f32 x) {inttofloat tmp; tmp.f=x; return tmp.u;}
391 #endif
392 
394  #define AIR(x) (IR(x)&0x7fffffff)
395 
397 #ifdef IRRLICHT_FAST_MATH
398  #define FR(x) ((f32&)(x))
399 #else
400  inline f32 FR(u32 x) {inttofloat tmp; tmp.u=x; return tmp.f;}
401  inline f32 FR(s32 x) {inttofloat tmp; tmp.s=x; return tmp.f;}
402 #endif
403 
405  #define IEEE_1_0 0x3f800000
406  #define IEEE_255_0 0x437f0000
408 
409 #ifdef IRRLICHT_FAST_MATH
410  #define F32_LOWER_0(f) (F32_AS_U32(f) > F32_SIGN_BIT)
411  #define F32_LOWER_EQUAL_0(f) (F32_AS_S32(f) <= F32_VALUE_0)
412  #define F32_GREATER_0(f) (F32_AS_S32(f) > F32_VALUE_0)
413  #define F32_GREATER_EQUAL_0(f) (F32_AS_U32(f) <= F32_SIGN_BIT)
414  #define F32_EQUAL_1(f) (F32_AS_U32(f) == F32_VALUE_1)
415  #define F32_EQUAL_0(f) ( (F32_AS_U32(f) & F32_EXPON_MANTISSA ) == F32_VALUE_0)
416 
417  // only same sign
418  #define F32_A_GREATER_B(a,b) (F32_AS_S32((a)) > F32_AS_S32((b)))
419 
420 #else
421 
422  #define F32_LOWER_0(n) ((n) < 0.0f)
423  #define F32_LOWER_EQUAL_0(n) ((n) <= 0.0f)
424  #define F32_GREATER_0(n) ((n) > 0.0f)
425  #define F32_GREATER_EQUAL_0(n) ((n) >= 0.0f)
426  #define F32_EQUAL_1(n) ((n) == 1.0f)
427  #define F32_EQUAL_0(n) ((n) == 0.0f)
428  #define F32_A_GREATER_B(a,b) ((a) > (b))
429 #endif
430 
431 
432 #ifndef REALINLINE
433  #ifdef _MSC_VER
434  #define REALINLINE __forceinline
435  #else
436  #define REALINLINE inline
437  #endif
438 #endif
439 
440 #if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
441 
442  // 8-bit bools in Borland builder
443 
445  REALINLINE u32 if_c_a_else_b ( const c8 condition, const u32 a, const u32 b )
446  {
447  return ( ( -condition >> 7 ) & ( a ^ b ) ) ^ b;
448  }
449 
451  REALINLINE u32 if_c_a_else_0 ( const c8 condition, const u32 a )
452  {
453  return ( -condition >> 31 ) & a;
454  }
455 #else
456 
458  REALINLINE u32 if_c_a_else_b ( const s32 condition, const u32 a, const u32 b )
459  {
460  return ( ( -condition >> 31 ) & ( a ^ b ) ) ^ b;
461  }
462 
464  REALINLINE u16 if_c_a_else_b ( const s16 condition, const u16 a, const u16 b )
465  {
466  return ( ( -condition >> 15 ) & ( a ^ b ) ) ^ b;
467  }
468 
470  REALINLINE u32 if_c_a_else_0 ( const s32 condition, const u32 a )
471  {
472  return ( -condition >> 31 ) & a;
473  }
474 #endif
475 
476  /*
477  if (condition) state |= m; else state &= ~m;
478  */
479  REALINLINE void setbit_cond ( u32 &state, s32 condition, u32 mask )
480  {
481  // 0, or any positive to mask
482  //s32 conmask = -condition >> 31;
483  state ^= ( ( -condition >> 31 ) ^ state ) & mask;
484  }
485 
486  inline f32 round_( f32 x )
487  {
488  return floorf( x + 0.5f );
489  }
490 
492  {
493 #ifdef IRRLICHT_FAST_MATH
494  return;
495  #ifdef feclearexcept
496  feclearexcept(FE_ALL_EXCEPT);
497  #elif defined(_MSC_VER)
498  __asm fnclex;
499  #elif defined(__GNUC__) && defined(__x86__)
500  __asm__ __volatile__ ("fclex \n\t");
501  #endif
502 #endif
503  }
504 
505  // calculate: sqrt ( x )
507  {
508  return sqrtf(f);
509  }
510 
511  // calculate: sqrt ( x )
513  {
514  return sqrt(f);
515  }
516 
517  // calculate: sqrt ( x )
519  {
520  return static_cast<s32>(squareroot(static_cast<f32>(f)));
521  }
522 
523 #ifdef __IRR_HAS_S64
524  // calculate: sqrt ( x )
526  {
527  return static_cast<s64>(squareroot(static_cast<f64>(f)));
528  }
529 #endif
530 
531  // calculate: 1 / sqrt ( x )
533  {
534  return 1.0 / sqrt(x);
535  }
536 
537  // calculate: 1 / sqrtf ( x )
539  {
540 #if defined ( IRRLICHT_FAST_MATH )
541  #if defined(_MSC_VER)
542  // SSE reciprocal square root estimate, accurate to 12 significant
543  // bits of the mantissa
544  f32 recsqrt;
545  __asm rsqrtss xmm0, f // xmm0 = rsqrtss(f)
546  __asm movss recsqrt, xmm0 // return xmm0
547  return recsqrt;
548 
549 /*
550  // comes from Nvidia
551  u32 tmp = (u32(IEEE_1_0 << 1) + IEEE_1_0 - *(u32*)&x) >> 1;
552  f32 y = *(f32*)&tmp;
553  return y * (1.47f - 0.47f * x * y * y);
554 */
555  #else
556  return 1.f / sqrtf(f);
557  #endif
558 #else // no fast math
559  return 1.f / sqrtf(f);
560 #endif
561  }
562 
563  // calculate: 1 / sqrtf( x )
565  {
566  return static_cast<s32>(reciprocal_squareroot(static_cast<f32>(x)));
567  }
568 
569  // calculate: 1 / x
571  {
572 #if defined (IRRLICHT_FAST_MATH)
573 
574  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
575  // bi ts of the mantissa
576  // One Newton-Raphson Iteration:
577  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
578 #if defined(_MSC_VER)
579  f32 rec;
580  __asm rcpss xmm0, f // xmm0 = rcpss(f)
581  __asm movss xmm1, f // xmm1 = f
582  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
583  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
584  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
585  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
586  // - f * rcpss(f) * rcpss(f)
587  __asm movss rec, xmm0 // return xmm0
588  return rec;
589 #else // no support yet for other compilers
590  return 1.f / f;
591 #endif
592  // instead set f to a high value to get a return value near zero..
594  // -1000000000000.f.. is use minus to stay negative..
595  // must test's here (plane.normal dot anything ) checks on <= 0.f
596  //u32 x = (-(AIR(f) != 0 ) >> 31 ) & ( IR(f) ^ 0xd368d4a5 ) ^ 0xd368d4a5;
597  //return 1.f / FR ( x );
598 
599 #else // no fast math
600  return 1.f / f;
601 #endif
602  }
603 
604  // calculate: 1 / x
606  {
607  return 1.0 / f;
608  }
609 
610 
611  // calculate: 1 / x, low precision allowed
613  {
614 #if defined( IRRLICHT_FAST_MATH)
615 
616  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
617  // bi ts of the mantissa
618  // One Newton-Raphson Iteration:
619  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
620 #if defined(_MSC_VER)
621  f32 rec;
622  __asm rcpss xmm0, f // xmm0 = rcpss(f)
623  __asm movss xmm1, f // xmm1 = f
624  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
625  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
626  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
627  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
628  // - f * rcpss(f) * rcpss(f)
629  __asm movss rec, xmm0 // return xmm0
630  return rec;
631 #else // no support yet for other compilers
632  return 1.f / f;
633 #endif
634 
635 /*
636  // SSE reciprocal estimate, accurate to 12 significant bits of
637  f32 rec;
638  __asm rcpss xmm0, f // xmm0 = rcpss(f)
639  __asm movss rec , xmm0 // return xmm0
640  return rec;
641 */
642 /*
643  register u32 x = 0x7F000000 - IR ( p );
644  const f32 r = FR ( x );
645  return r * (2.0f - p * r);
646 */
647 #else // no fast math
648  return 1.f / f;
649 #endif
650  }
651 
652 
654  {
655 #ifdef IRRLICHT_FAST_MATH
656  const f32 h = 0.5f;
657 
658  s32 t;
659 
660 #if defined(_MSC_VER)
661  __asm
662  {
663  fld x
664  fsub h
665  fistp t
666  }
667 #elif defined(__GNUC__)
668  __asm__ __volatile__ (
669  "fsub %2 \n\t"
670  "fistpl %0"
671  : "=m" (t)
672  : "t" (x), "f" (h)
673  : "st"
674  );
675 #else
676  return (s32) floorf ( x );
677 #endif
678  return t;
679 #else // no fast math
680  return (s32) floorf ( x );
681 #endif
682  }
683 
684 
686  {
687 #ifdef IRRLICHT_FAST_MATH
688  const f32 h = 0.5f;
689 
690  s32 t;
691 
692 #if defined(_MSC_VER)
693  __asm
694  {
695  fld x
696  fadd h
697  fistp t
698  }
699 #elif defined(__GNUC__)
700  __asm__ __volatile__ (
701  "fadd %2 \n\t"
702  "fistpl %0 \n\t"
703  : "=m"(t)
704  : "t"(x), "f"(h)
705  : "st"
706  );
707 #else
708  return (s32) ceilf ( x );
709 #endif
710  return t;
711 #else // not fast math
712  return (s32) ceilf ( x );
713 #endif
714  }
715 
716 
717 
719  {
720 #if defined(IRRLICHT_FAST_MATH)
721  s32 t;
722 
723 #if defined(_MSC_VER)
724  __asm
725  {
726  fld x
727  fistp t
728  }
729 #elif defined(__GNUC__)
730  __asm__ __volatile__ (
731  "fistpl %0 \n\t"
732  : "=m"(t)
733  : "t"(x)
734  : "st"
735  );
736 #else
737  return (s32) round_(x);
738 #endif
739  return t;
740 #else // no fast math
741  return (s32) round_(x);
742 #endif
743  }
744 
745  inline f32 f32_max3(const f32 a, const f32 b, const f32 c)
746  {
747  return a > b ? (a > c ? a : c) : (b > c ? b : c);
748  }
749 
750  inline f32 f32_min3(const f32 a, const f32 b, const f32 c)
751  {
752  return a < b ? (a < c ? a : c) : (b < c ? b : c);
753  }
754 
755  inline f32 fract ( f32 x )
756  {
757  return x - floorf ( x );
758  }
759 
760 } // end namespace core
761 } // end namespace irr
762 
763 #ifndef IRRLICHT_FAST_MATH
764  using irr::core::IR;
765  using irr::core::FR;
766 #endif
767 
768 #endif
769 
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
signed short s16
16 bit signed variable.
Definition: irrTypes.h:52
const f32 PI
Constant for PI.
Definition: irrMath.h:57
const f64 PI64
Constant for 64bit PI.
Definition: irrMath.h:69
unsigned long long u64
64 bit unsigned variable.
Definition: irrTypes.h:86
REALINLINE s32 round32(f32 x)
Definition: irrMath.h:718
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition: irrMath.h:307
f32 degToRad(f32 degrees)
Utility function to convert a degrees value to radians.
Definition: irrMath.h:108
s32 s32_clamp(s32 value, s32 low, s32 high)
Definition: irrMath.h:356
f32 f32_max3(const f32 a, const f32 b, const f32 c)
Definition: irrMath.h:745
u32 IR(f32 x)
Definition: irrMath.h:390
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
REALINLINE void clearFPUException()
Definition: irrMath.h:491
const f32 RADTODEG
32bit constant for converting from radians to degrees (formally known as GRAD_PI)
Definition: irrMath.h:78
char c8
8 bit character variable.
Definition: irrTypes.h:35
bool equalsByUlp(f32 a, f32 b, int maxUlpDiff)
We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exi...
Definition: irrMath.h:278
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:506
f32 fract(f32 x)
Definition: irrMath.h:755
const f32 HALF_PI
Constant for half of PI.
Definition: irrMath.h:63
s32 s32_min(s32 a, s32 b)
Definition: irrMath.h:344
bool equalsRelative(const T a, const T b, const T factor=relativeErrorFactor< T >())
Definition: irrMath.h:255
s32 s32_max(s32 a, s32 b)
Definition: irrMath.h:350
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
REALINLINE s32 ceil32(f32 x)
Definition: irrMath.h:685
REALINLINE f32 reciprocal_approxim(const f32 f)
Definition: irrMath.h:612
T lerp(const T &a, const T &b, const f32 t)
Definition: irrMath.h:160
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
long long s64
64 bit signed variable.
Definition: irrTypes.h:100
T roundingError()
Definition: irrMath.h:189
unsigned short u16
16 bit unsigned variable.
Definition: irrTypes.h:44
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
const f32 ROUNDING_ERROR_f32
Definition: irrMath.h:50
const f32 RECIPROCAL_PI
Constant for reciprocal of PI.
Definition: irrMath.h:60
bool isnotzero(const f32 a, const f32 tolerance=ROUNDING_ERROR_f32)
returns if a equals not zero, taking rounding errors into account
Definition: irrMath.h:319
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
const f64 ROUNDING_ERROR_f64
Definition: irrMath.h:51
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
REALINLINE void setbit_cond(u32 &state, s32 condition, u32 mask)
Definition: irrMath.h:479
REALINLINE f32 reciprocal(const f32 f)
Definition: irrMath.h:570
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
const s64 ROUNDING_ERROR_S64
Definition: irrMath.h:48
const T & min_(const T &a, const T &b)
returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)
Definition: irrMath.h:124
REALINLINE u32 if_c_a_else_b(const s32 condition, const u32 a, const u32 b)
conditional set based on mask and arithmetic shift
Definition: irrMath.h:458
const f32 DEGTORAD
32bit Constant for converting from degrees to radians
Definition: irrMath.h:75
f32 FR(u32 x)
Floating-point representation of an integer value.
Definition: irrMath.h:400
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition: irrMath.h:178
const T & max_(const T &a, const T &b)
returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)
Definition: irrMath.h:138
FloatIntUnion32(float f1=0.0f)
Definition: irrMath.h:268
f32 radToDeg(f32 radians)
Utility function to convert a radian value to degrees.
Definition: irrMath.h:90
REALINLINE u32 if_c_a_else_0(const s32 condition, const u32 a)
conditional set based on mask and arithmetic shift
Definition: irrMath.h:470
const f64 RECIPROCAL_PI64
Constant for 64bit reciprocal of PI.
Definition: irrMath.h:72
f32 round_(f32 x)
Definition: irrMath.h:486
#define REALINLINE
Definition: irrMath.h:436
REALINLINE s32 floor32(f32 x)
Definition: irrMath.h:653
const s32 ROUNDING_ERROR_S32
Rounding error constant often used when comparing f32 values.
Definition: irrMath.h:45
f32 f32_min3(const f32 a, const f32 b, const f32 c)
Definition: irrMath.h:750
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:532
T relativeErrorFactor()
Definition: irrMath.h:227
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167
T abs_(const T &a)
returns abs of two values. Own implementation to get rid of STL (VS6 problems)
Definition: irrMath.h:152