arsa  2.7
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  const FloatIntUnion32 fa(a);
287  const 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  const 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 
471  {
472  return ( -condition >> 31 ) & a;
473  }
474 #endif
475 
476  /*
477  if (condition) state |= m; else state &= ~m;
478  */
480  {
481  // 0, or any positive to mask
482  //s32 conmask = -condition >> 31;
483  state ^= ( ( -condition >> 31 ) ^ state ) & mask;
484  }
485 
486  // NOTE: This is not as exact as the c99/c++11 round function, especially at high numbers starting with 8388609
487  // (only low number which seems to go wrong is 0.49999997 which is rounded to 1)
488  // Also negative 0.5 is rounded up not down unlike with the standard function (p.E. input -0.5 will be 0 and not -1)
489  inline f32 round_( f32 x )
490  {
491  return floorf( x + 0.5f );
492  }
493 
494  // calculate: sqrt ( x )
496  {
497  return sqrtf(f);
498  }
499 
500  // calculate: sqrt ( x )
502  {
503  return sqrt(f);
504  }
505 
506  // calculate: sqrt ( x )
508  {
509  return static_cast<s32>(squareroot(static_cast<f32>(f)));
510  }
511 
512 #ifdef __IRR_HAS_S64
513  // calculate: sqrt ( x )
515  {
516  return static_cast<s64>(squareroot(static_cast<f64>(f)));
517  }
518 #endif
519 
520  // calculate: 1 / sqrt ( x )
522  {
523  return 1.0 / sqrt(x);
524  }
525 
526  // calculate: 1 / sqrtf ( x )
528  {
529 #if defined ( IRRLICHT_FAST_MATH )
530  // NOTE: Unlike comment below says I found inaccuracies already at 4'th significant bit.
531  // p.E: Input 1, expected 1, got 0.999755859
532 
533  #if defined(_MSC_VER) && !defined(_WIN64)
534  // SSE reciprocal square root estimate, accurate to 12 significant
535  // bits of the mantissa
536  f32 recsqrt;
537  __asm rsqrtss xmm0, f // xmm0 = rsqrtss(f)
538  __asm movss recsqrt, xmm0 // return xmm0
539  return recsqrt;
540 
541 /*
542  // comes from Nvidia
543  u32 tmp = (u32(IEEE_1_0 << 1) + IEEE_1_0 - *(u32*)&x) >> 1;
544  f32 y = *(f32*)&tmp;
545  return y * (1.47f - 0.47f * x * y * y);
546 */
547  #else
548  return 1.f / sqrtf(f);
549  #endif
550 #else // no fast math
551  return 1.f / sqrtf(f);
552 #endif
553  }
554 
555  // calculate: 1 / sqrtf( x )
557  {
558  return static_cast<s32>(reciprocal_squareroot(static_cast<f32>(x)));
559  }
560 
561  // calculate: 1 / x
563  {
564 #if defined (IRRLICHT_FAST_MATH)
565  // NOTE: Unlike with 1.f / f the values very close to 0 return -nan instead of inf
566 
567  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
568  // bi ts of the mantissa
569  // One Newton-Raphson Iteration:
570  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
571 #if defined(_MSC_VER) && !defined(_WIN64)
572  f32 rec;
573  __asm rcpss xmm0, f // xmm0 = rcpss(f)
574  __asm movss xmm1, f // xmm1 = f
575  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
576  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
577  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
578  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
579  // - f * rcpss(f) * rcpss(f)
580  __asm movss rec, xmm0 // return xmm0
581  return rec;
582 #else // no support yet for other compilers
583  return 1.f / f;
584 #endif
585  // instead set f to a high value to get a return value near zero..
587  // -1000000000000.f.. is use minus to stay negative..
588  // must test's here (plane.normal dot anything ) checks on <= 0.f
589  //u32 x = (-(AIR(f) != 0 ) >> 31 ) & ( IR(f) ^ 0xd368d4a5 ) ^ 0xd368d4a5;
590  //return 1.f / FR ( x );
591 
592 #else // no fast math
593  return 1.f / f;
594 #endif
595  }
596 
597  // calculate: 1 / x
599  {
600  return 1.0 / f;
601  }
602 
603 
604  // calculate: 1 / x, low precision allowed
606  {
607 #if defined( IRRLICHT_FAST_MATH)
608 
609  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
610  // bi ts of the mantissa
611  // One Newton-Raphson Iteration:
612  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
613 #if defined(_MSC_VER) && !defined(_WIN64)
614  f32 rec;
615  __asm rcpss xmm0, f // xmm0 = rcpss(f)
616  __asm movss xmm1, f // xmm1 = f
617  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
618  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
619  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
620  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
621  // - f * rcpss(f) * rcpss(f)
622  __asm movss rec, xmm0 // return xmm0
623  return rec;
624 #else // no support yet for other compilers
625  return 1.f / f;
626 #endif
627 
628 /*
629  // SSE reciprocal estimate, accurate to 12 significant bits of
630  f32 rec;
631  __asm rcpss xmm0, f // xmm0 = rcpss(f)
632  __asm movss rec , xmm0 // return xmm0
633  return rec;
634 */
635 /*
636  register u32 x = 0x7F000000 - IR ( p );
637  const f32 r = FR ( x );
638  return r * (2.0f - p * r);
639 */
640 #else // no fast math
641  return 1.f / f;
642 #endif
643  }
644 
645 
647  {
648  return (s32) floorf ( x );
649  }
650 
652  {
653  return (s32) ceilf ( x );
654  }
655 
656  // NOTE: Please check round_ documentation about some inaccuracies in this compared to standard library round function.
658  {
659  return (s32) round_(x);
660  }
661 
662  inline f32 f32_max3(const f32 a, const f32 b, const f32 c)
663  {
664  return a > b ? (a > c ? a : c) : (b > c ? b : c);
665  }
666 
667  inline f32 f32_min3(const f32 a, const f32 b, const f32 c)
668  {
669  return a < b ? (a < c ? a : c) : (b < c ? b : c);
670  }
671 
672  inline f32 fract ( f32 x )
673  {
674  return x - floorf ( x );
675  }
676 
677 } // end namespace core
678 } // end namespace irr
679 
680 #ifndef IRRLICHT_FAST_MATH
681  using irr::core::IR;
682  using irr::core::FR;
683 #endif
684 
685 #endif
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:657
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
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
f32 f32_max3(const f32 a, const f32 b, const f32 c)
Definition: irrMath.h:662
u32 IR(f32 x)
Definition: irrMath.h:390
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
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:495
f32 fract(f32 x)
Definition: irrMath.h:672
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: CARSADPad.h:6
REALINLINE s32 ceil32(f32 x)
Definition: irrMath.h:651
REALINLINE f32 reciprocal_approxim(const f32 f)
Definition: irrMath.h:605
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:562
GLsizei const GLfloat * value
GLfloat f
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
GLenum GLint GLuint mask
GLboolean GLboolean GLboolean b
GLdouble s
Definition: SDL_opengl.h:2063
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
FloatIntUnion32(float f1=0.0f)
Definition: irrMath.h:268
GLenum condition
f32 radToDeg(f32 radians)
Utility function to convert a radian value to degrees.
Definition: irrMath.h:90
GLboolean GLboolean GLboolean GLboolean a
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:489
#define REALINLINE
Definition: irrMath.h:436
REALINLINE s32 floor32(f32 x)
Definition: irrMath.h:646
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:667
const GLubyte * c
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521
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