Saga3D API Documentation  1.0-RC4
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 "SagaConfig.h"
9 #include <cmath>
10 #include <cfloat>
11 #include <cstdlib> // for abs() etc.
12 #include <climits> // For INT_MAX / UINT_MAX
13 #include <cstdint>
14 #include <glm/vec3.hpp>
15 #include <glm/gtx/norm.hpp>
16 
17 namespace saga
18 {
19 namespace core
20 {
21 
23 
24  const std::int32_t ROUNDING_ERROR_S32 = 0;
25 
26 #ifdef __IRR_HAS_S64
27  const std::int64_t ROUNDING_ERROR_S64 = 0;
28 #endif
29  const float ROUNDING_ERROR_float = 0.000001f;
30  const double ROUNDING_ERROR_double = 0.00000001;
31 
32 #ifdef PI // make sure we don't collide with a define
33 #undef PI
34 #endif
35  const float PI = 3.14159265359f;
37 
39  const float RECIPROCAL_PI = 1.0f/PI;
40 
42  const float HALF_PI = PI/2.0f;
43 
44 #ifdef PI64 // make sure we don't collide with a define
45 #undef PI64
46 #endif
47  const double PI64 = 3.1415926535897932384626433832795028841971693993751;
49 
51  const double RECIPROCAL_PI64 = 1.0/PI64;
52 
54  const float DEGTORAD = PI / 180.0f;
55 
57  const float RADTODEG = 180.0f / PI;
58 
60  const double DEGTORAD64 = PI64 / 180.0;
61 
63  const double RADTODEG64 = 180.0 / PI64;
64 
65  inline bool isBetweenPoints(const glm::vec3& point, const glm::vec3& begin, const glm::vec3& end)
66  {
67  const auto f = glm::length2(end - begin);
68  return glm::distance2(point, begin) <= f && glm::distance2(point, end) <= f;
69  }
70 
71  inline glm::vec3 getHorizontalAngle(const glm::vec3& vec)
72  {
73  glm::vec3 angle;
74 
75  const double tmp = (atan2((double)vec.x, (double)vec.z) * RADTODEG64);
76  angle.y = tmp;
77 
78  if (angle.y < 0)
79  angle.y += 360;
80  if (angle.y >= 360)
81  angle.y -= 360;
82 
83  const double z1 = glm::sqrt(vec.x*vec.x + vec.z*vec.z);
84 
85  angle.x = (atan2((double)z1, (double)vec.y) * RADTODEG64 - 90.0);
86 
87  if (angle.x < 0)
88  angle.x += 360;
89  if (angle.x >= 360)
90  angle.x -= 360;
91 
92  return angle;
93  }
94 
95  inline glm::vec3 rotationToDirection(const glm::vec3& vec, const glm::vec3& forwards = {0, 0, 1})
96  {
97  const double cr = cos( core::DEGTORAD64 * vec.x );
98  const double sr = sin( core::DEGTORAD64 * vec.x );
99  const double cp = cos( core::DEGTORAD64 * vec.y );
100  const double sp = sin( core::DEGTORAD64 * vec.y );
101  const double cy = cos( core::DEGTORAD64 * vec.z );
102  const double sy = sin( core::DEGTORAD64 * vec.z );
103 
104  const double srsp = sr*sp;
105  const double crsp = cr*sp;
106 
107  const double pseudoMatrix[] = {
108  ( cp*cy ), ( cp*sy ), ( -sp ),
109  ( srsp*cy-cr*sy ), ( srsp*sy+cr*cy ), ( sr*cp ),
110  ( crsp*cy+sr*sy ), ( crsp*sy-sr*cy ), ( cr*cp )};
111 
112  return {
113  (forwards.x * pseudoMatrix[0] +
114  forwards.y * pseudoMatrix[3] +
115  forwards.z * pseudoMatrix[6]),
116  (forwards.x * pseudoMatrix[1] +
117  forwards.y * pseudoMatrix[4] +
118  forwards.z * pseudoMatrix[7]),
119  (forwards.x * pseudoMatrix[2] +
120  forwards.y * pseudoMatrix[5] +
121  forwards.z * pseudoMatrix[8])
122  };
123  }
124 
126 
129  inline float radToDeg(float radians)
130  {
131  return RADTODEG * radians;
132  }
133 
135 
138  inline double radToDeg(double radians)
139  {
140  return RADTODEG64 * radians;
141  }
142 
144 
147  inline float degToRad(float degrees)
148  {
149  return DEGTORAD * degrees;
150  }
151 
153 
156  inline double degToRad(double degrees)
157  {
158  return DEGTORAD64 * degrees;
159  }
160 
162  template<class T>
163  inline const T& min_(const T& a, const T& b)
164  {
165  return a < b ? a : b;
166  }
167 
169  template<class T>
170  inline const T& min_(const T& a, const T& b, const T& c)
171  {
172  return a < b ? min_(a, c) : min_(b, c);
173  }
174 
176  template<class T>
177  inline const T& max_(const T& a, const T& b)
178  {
179  return a < b ? b : a;
180  }
181 
183  template<class T>
184  inline const T& max_(const T& a, const T& b, const T& c)
185  {
186  return a < b ? max_(b, c) : max_(a, c);
187  }
188 
190  template<class T>
191  inline T abs_(const T& a)
192  {
193  return a < (T)0 ? -a : a;
194  }
195 
198  template<class T>
199  inline T lerp(const T& a, const T& b, const float t)
200  {
201  return (T)(a*(1.f-t)) + (b*t);
202  }
203 
205  template <class T>
206  inline const T clamp (const T& value, const T& low, const T& high)
207  {
208  return min_ (max_(value,low), high);
209  }
210 
212  // Note: We use the same trick as boost and use two template arguments to
213  // avoid ambiguity when swapping objects of an Irrlicht type that has not
214  // it's own swap overload. Otherwise we get conflicts with some compilers
215  // in combination with stl.
216  template <class T1, class T2>
217  inline void swap(T1& a, T2& b)
218  {
219  T1 c(a);
220  a = b;
221  b = c;
222  }
223 
224  template <class T>
225  inline T roundingError();
226 
227  template <>
228  inline float roundingError()
229  {
230  return ROUNDING_ERROR_float;
231  }
232 
233  template <>
234  inline double roundingError()
235  {
236  return ROUNDING_ERROR_double;
237  }
238 
239  template <>
240  inline std::int32_t roundingError()
241  {
242  return ROUNDING_ERROR_S32;
243  }
244 
245  template <>
246  inline std::uint32_t roundingError()
247  {
248  return ROUNDING_ERROR_S32;
249  }
250 
251 #ifdef __IRR_HAS_S64
252  template <>
253  inline std::int64_t roundingError()
254  {
255  return ROUNDING_ERROR_S64;
256  }
257 
258  template <>
259  inline std::uint64_t roundingError()
260  {
261  return ROUNDING_ERROR_S64;
262  }
263 #endif
264 
265  template <class T>
267  {
268  return 1;
269  }
270 
271  template <>
272  inline float relativeErrorFactor()
273  {
274  return 4;
275  }
276 
277  template <>
278  inline double relativeErrorFactor()
279  {
280  return 8;
281  }
282 
284  template <class T>
285  inline bool equals(const T a, const T b, const T tolerance = roundingError<T>())
286  {
287  return (a + tolerance >= b) && (a - tolerance <= b);
288  }
289 
290 
293  template <class T>
294  inline bool equalsRelative(const T a, const T b, const T factor = relativeErrorFactor<T>())
295  {
296  //https://eagergames.wordpress.com/2017/04/01/fast-parallel-lines-and-vectors-test/
297 
298  const T maxi = max_(a, b);
299  const T mini = min_(a, b);
300  const T maxMagnitude = max_(maxi, -mini);
301 
302  return (maxMagnitude*factor + maxi) == (maxMagnitude*factor + mini); // MAD Wise
303  }
304 
306  {
307  FloatIntUnion32(float f1 = 0.0f) : f(f1) {}
308  // Portable sign-extraction
309  bool sign() const { return (i >> 31) != 0; }
310 
311  std::int32_t i;
312  float f;
313  };
314 
316  //\result true when numbers have a ULP <= maxUlpDiff AND have the same sign.
317  inline bool equalsByUlp(float a, float b, int maxUlpDiff)
318  {
319  // Based on the ideas and code from Bruce Dawson on
320  // http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/
321  // When floats are interpreted as integers the two nearest possible float numbers differ just
322  // by one integer number. Also works the other way round, an integer of 1 interpreted as float
323  // is for example the smallest possible float number.
324 
325  FloatIntUnion32 fa(a);
326  FloatIntUnion32 fb(b);
327 
328  // Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better.
329  if (fa.sign() != fb.sign())
330  {
331  // Check for equality to make sure +0==-0
332  if (fa.i == fb.i)
333  return true;
334  return false;
335  }
336 
337  // Find the difference in ULPs.
338  int ulpsDiff = abs_(fa.i- fb.i);
339  if (ulpsDiff <= maxUlpDiff)
340  return true;
341 
342  return false;
343  }
344 
346  inline bool iszero(const double a, const double tolerance = ROUNDING_ERROR_double)
347  {
348  return fabs(a) <= tolerance;
349  }
350 
352  inline bool iszero(const float a, const float tolerance = ROUNDING_ERROR_float)
353  {
354  return fabsf(a) <= tolerance;
355  }
356 
358  inline bool isnotzero(const float a, const float tolerance = ROUNDING_ERROR_float)
359  {
360  return fabsf(a) > tolerance;
361  }
362 
364  inline bool iszero(const std::int32_t a, const std::int32_t tolerance = 0)
365  {
366  return (a & 0x7ffffff) <= tolerance;
367  }
368 
370  inline bool iszero(const std::uint32_t a, const std::uint32_t tolerance = 0)
371  {
372  return a <= tolerance;
373  }
374 
375 #ifdef __IRR_HAS_S64
376  inline bool iszero(const std::int64_t a, const std::int64_t tolerance = 0)
378  {
379  return abs_(a) <= tolerance;
380  }
381 #endif
382 
383  inline std::int32_t s32_min(std::int32_t a, std::int32_t b)
384  {
385  const std::int32_t mask = (a - b) >> 31;
386  return (a & mask) | (b & ~mask);
387  }
388 
389  inline std::int32_t s32_max(std::int32_t a, std::int32_t b)
390  {
391  const std::int32_t mask = (a - b) >> 31;
392  return (b & mask) | (a & ~mask);
393  }
394 
395  inline std::int32_t s32_clamp(std::int32_t value, std::int32_t low, std::int32_t high)
396  {
397  return s32_min(s32_max(value,low), high);
398  }
399 
400  /*
401  float IEEE-754 bit representation
402 
403  0 0x00000000
404  1.0 0x3f800000
405  0.5 0x3f000000
406  3 0x40400000
407  +inf 0x7f800000
408  -inf 0xff800000
409  +NaN 0x7fc00000 or 0x7ff00000
410  in general: number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits)
411  */
412 
413  typedef union { std::uint32_t u; std::int32_t s; float f; } inttofloat;
414 
415  #define F32_AS_S32(f) (*((std::int32_t *) &(f)))
416  #define F32_AS_U32(f) (*((std::uint32_t *) &(f)))
417  #define F32_AS_U32_POINTER(f) (((std::uint32_t *) &(f)))
418 
419  #define F32_VALUE_0 0x00000000
420  #define F32_VALUE_1 0x3f800000
421  #define F32_SIGN_BIT 0x80000000U
422  #define F32_EXPON_MANTISSA 0x7FFFFFFFU
423 
426 #ifdef IRRLICHT_FAST_MATH
427  #define IR(x) ((std::uint32_t&)(x))
428 #else
429  inline std::uint32_t IR(float x) {inttofloat tmp; tmp.f=x; return tmp.u;}
430 #endif
431 
433  #define AIR(x) (IR(x)&0x7fffffff)
434 
436 #ifdef IRRLICHT_FAST_MATH
437  #define FR(x) ((float&)(x))
438 #else
439  inline float FR(std::uint32_t x) {inttofloat tmp; tmp.u=x; return tmp.f;}
440  inline float FR(std::int32_t x) {inttofloat tmp; tmp.s=x; return tmp.f;}
441 #endif
442 
444  #define IEEE_1_0 0x3f800000
445  #define IEEE_255_0 0x437f0000
447 
448 #ifdef IRRLICHT_FAST_MATH
449  #define F32_LOWER_0(f) (F32_AS_U32(f) > F32_SIGN_BIT)
450  #define F32_LOWER_EQUAL_0(f) (F32_AS_S32(f) <= F32_VALUE_0)
451  #define F32_GREATER_0(f) (F32_AS_S32(f) > F32_VALUE_0)
452  #define F32_GREATER_EQUAL_0(f) (F32_AS_U32(f) <= F32_SIGN_BIT)
453  #define F32_EQUAL_1(f) (F32_AS_U32(f) == F32_VALUE_1)
454  #define F32_EQUAL_0(f) ((F32_AS_U32(f) & F32_EXPON_MANTISSA) == F32_VALUE_0)
455 
456  // only same sign
457  #define F32_A_GREATER_B(a,b) (F32_AS_S32((a)) > F32_AS_S32((b)))
458 
459 #else
460 
461  #define F32_LOWER_0(n) ((n) < 0.0f)
462  #define F32_LOWER_EQUAL_0(n) ((n) <= 0.0f)
463  #define F32_GREATER_0(n) ((n) > 0.0f)
464  #define F32_GREATER_EQUAL_0(n) ((n) >= 0.0f)
465  #define F32_EQUAL_1(n) ((n) == 1.0f)
466  #define F32_EQUAL_0(n) ((n) == 0.0f)
467  #define F32_A_GREATER_B(a,b) ((a) > (b))
468 #endif
469 
470 
471 #ifndef REALINLINE
472  #ifdef _MSC_VER
473  #define REALINLINE __forceinline
474  #else
475  #define REALINLINE inline
476  #endif
477 #endif
478 
479 #if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
480 
481  // 8-bit bools in Borland builder
482 
484  REALINLINE std::uint32_t if_c_a_else_b (const char condition, const std::uint32_t a, const std::uint32_t b)
485  {
486  return ((-condition >> 7) & (a ^ b)) ^ b;
487  }
488 
490  REALINLINE std::uint32_t if_c_a_else_0 (const char condition, const std::uint32_t a)
491  {
492  return (-condition >> 31) & a;
493  }
494 #else
495 
497  REALINLINE std::uint32_t if_c_a_else_b (const std::int32_t condition, const std::uint32_t a, const std::uint32_t b)
498  {
499  return ((-condition >> 31) & (a ^ b)) ^ b;
500  }
501 
503  REALINLINE std::uint16_t if_c_a_else_b (const std::int16_t condition, const std::uint16_t a, const std::uint16_t b)
504  {
505  return ((-condition >> 15) & (a ^ b)) ^ b;
506  }
507 
509  REALINLINE std::uint32_t if_c_a_else_0 (const std::int32_t condition, const std::uint32_t a)
510  {
511  return (-condition >> 31) & a;
512  }
513 #endif
514 
515  /*
516  if (condition) state |= m; else state &= ~m;
517  */
518  REALINLINE void setbit_cond (std::uint32_t &state, std::int32_t condition, std::uint32_t mask)
519  {
520  // 0, or any positive to mask
521  //std::int32_t conmask = -condition >> 31;
522  state ^= ((-condition >> 31) ^ state) & mask;
523  }
524 
525  inline float round_(float x)
526  {
527  return floorf(x + 0.5f);
528  }
529 
531  {
532 #ifdef IRRLICHT_FAST_MATH
533  return;
534  #ifdef feclearexcept
535  feclearexcept(FE_ALL_EXCEPT);
536  #elif defined(_MSC_VER)
537  __asm fnclex;
538  #elif defined(__GNUC__) && defined(__x86__)
539  __asm__ __volatile__ ("fclex \n\t");
540  #endif
541 #endif
542  }
543 
544  // calculate: sqrt (x)
545  REALINLINE float squareroot(const float f)
546  {
547  return sqrtf(f);
548  }
549 
550  // calculate: sqrt (x)
551  REALINLINE double squareroot(const double f)
552  {
553  return sqrt(f);
554  }
555 
556  // calculate: sqrt (x)
557  REALINLINE std::int32_t squareroot(const std::int32_t f)
558  {
559  return static_cast<std::int32_t>(squareroot(static_cast<float>(f)));
560  }
561 
562 #ifdef __IRR_HAS_S64
563  // calculate: sqrt (x)
564  REALINLINE std::int64_t squareroot(const std::int64_t f)
565  {
566  return static_cast<std::int64_t>(squareroot(static_cast<double>(f)));
567  }
568 #endif
569 
570  // calculate: 1 / sqrt (x)
571  REALINLINE double reciprocal_squareroot(const double x)
572  {
573  return 1.0 / sqrt(x);
574  }
575 
576  // calculate: 1 / sqrtf (x)
577  REALINLINE float reciprocal_squareroot(const float f)
578  {
579 #if defined (IRRLICHT_FAST_MATH)
580  #if defined(_MSC_VER)
581  // SSE reciprocal square root estimate, accurate to 12 significant
582  // bits of the mantissa
583  float recsqrt;
584  __asm rsqrtss xmm0, f // xmm0 = rsqrtss(f)
585  __asm movss recsqrt, xmm0 // return xmm0
586  return recsqrt;
587 
588 /*
589  // comes from Nvidia
590  std::uint32_t tmp = (std::uint32_t(IEEE_1_0 << 1) + IEEE_1_0 - *(std::uint32_t*)&x) >> 1;
591  float y = *(float*)&tmp;
592  return y * (1.47f - 0.47f * x * y * y);
593 */
594  #else
595  return 1.f / sqrtf(f);
596  #endif
597 #else // no fast math
598  return 1.f / sqrtf(f);
599 #endif
600  }
601 
602  // calculate: 1 / sqrtf(x)
603  REALINLINE std::int32_t reciprocal_squareroot(const std::int32_t x)
604  {
605  return static_cast<std::int32_t>(reciprocal_squareroot(static_cast<float>(x)));
606  }
607 
608  // calculate: 1 / x
609  REALINLINE float reciprocal(const float f)
610  {
611 #if defined (IRRLICHT_FAST_MATH)
612 
613  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
614  // bi ts of the mantissa
615  // One Newton-Raphson Iteration:
616  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
617 #if defined(_MSC_VER)
618  float rec;
619  __asm rcpss xmm0, f // xmm0 = rcpss(f)
620  __asm movss xmm1, f // xmm1 = f
621  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
622  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
623  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
624  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
625  // - f * rcpss(f) * rcpss(f)
626  __asm movss rec, xmm0 // return xmm0
627  return rec;
628 #else // no support yet for other compilers
629  return 1.f / f;
630 #endif
631  // instead set f to a high value to get a return value near zero..
633  // -1000000000000.f.. is use minus to stay negative..
634  // must test's here (plane.normal dot anything) checks on <= 0.f
635  //std::uint32_t x = (-(AIR(f) != 0) >> 31) & (IR(f) ^ 0xd368d4a5) ^ 0xd368d4a5;
636  //return 1.f / FR (x);
637 
638 #else // no fast math
639  return 1.f / f;
640 #endif
641  }
642 
643  // calculate: 1 / x
644  REALINLINE double reciprocal (const double f)
645  {
646  return 1.0 / f;
647  }
648 
649 
650  // calculate: 1 / x, low precision allowed
651  REALINLINE float reciprocal_approxim (const float f)
652  {
653 #if defined(IRRLICHT_FAST_MATH)
654 
655  // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant
656  // bi ts of the mantissa
657  // One Newton-Raphson Iteration:
658  // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)
659 #if defined(_MSC_VER)
660  float rec;
661  __asm rcpss xmm0, f // xmm0 = rcpss(f)
662  __asm movss xmm1, f // xmm1 = f
663  __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f)
664  __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f)
665  __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f)
666  __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f)
667  // - f * rcpss(f) * rcpss(f)
668  __asm movss rec, xmm0 // return xmm0
669  return rec;
670 #else // no support yet for other compilers
671  return 1.f / f;
672 #endif
673 
674 /*
675  // SSE reciprocal estimate, accurate to 12 significant bits of
676  float rec;
677  __asm rcpss xmm0, f // xmm0 = rcpss(f)
678  __asm movss rec , xmm0 // return xmm0
679  return rec;
680 */
681 /*
682  register std::uint32_t x = 0x7F000000 - IR (p);
683  const float r = FR (x);
684  return r * (2.0f - p * r);
685 */
686 #else // no fast math
687  return 1.f / f;
688 #endif
689  }
690 
691 
692  REALINLINE std::int32_t floor32(float x)
693  {
694 #ifdef IRRLICHT_FAST_MATH
695  const float h = 0.5f;
696 
697  std::int32_t t;
698 
699 #if defined(_MSC_VER)
700  __asm
701  {
702  fld x
703  fsub h
704  fistp t
705  }
706 #elif defined(__GNUC__)
707  __asm__ __volatile__ (
708  "fsub %2 \n\t"
709  "fistpl %0"
710  : "=m" (t)
711  : "t" (x), "f" (h)
712  : "st"
713  );
714 #else
715  return (std::int32_t) floorf (x);
716 #endif
717  return t;
718 #else // no fast math
719  return (std::int32_t) floorf (x);
720 #endif
721  }
722 
723 
724  REALINLINE std::int32_t ceil32 (float x)
725  {
726 #ifdef IRRLICHT_FAST_MATH
727  const float h = 0.5f;
728 
729  std::int32_t t;
730 
731 #if defined(_MSC_VER)
732  __asm
733  {
734  fld x
735  fadd h
736  fistp t
737  }
738 #elif defined(__GNUC__)
739  __asm__ __volatile__ (
740  "fadd %2 \n\t"
741  "fistpl %0 \n\t"
742  : "=m"(t)
743  : "t"(x), "f"(h)
744  : "st"
745  );
746 #else
747  return (std::int32_t) ceilf (x);
748 #endif
749  return t;
750 #else // not fast math
751  return (std::int32_t) ceilf (x);
752 #endif
753  }
754 
755 
756 
757  REALINLINE std::int32_t round32(float x)
758  {
759 #if defined(IRRLICHT_FAST_MATH)
760  std::int32_t t;
761 
762 #if defined(_MSC_VER)
763  __asm
764  {
765  fld x
766  fistp t
767  }
768 #elif defined(__GNUC__)
769  __asm__ __volatile__ (
770  "fistpl %0 \n\t"
771  : "=m"(t)
772  : "t"(x)
773  : "st"
774  );
775 #else
776  return (std::int32_t) round_(x);
777 #endif
778  return t;
779 #else // no fast math
780  return (std::int32_t) round_(x);
781 #endif
782  }
783 
784  inline float float_max3(const float a, const float b, const float c)
785  {
786  return a > b ? (a > c ? a : c) : (b > c ? b : c);
787  }
788 
789  inline float float_min3(const float a, const float b, const float c)
790  {
791  return a < b ? (a < c ? a : c) : (b < c ? b : c);
792  }
793 
794  inline float fract (float x)
795  {
796  return x - floorf (x);
797  }
798 
799 } // namespace core
800 } // namespace saga
801 
802 #ifndef IRRLICHT_FAST_MATH
803  using saga::core::IR;
804  using saga::core::FR;
805 #endif
806 
807 #endif
808 
saga::core::equalsRelative
bool equalsRelative(const T a, const T b, const T factor=relativeErrorFactor< T >())
Definition: irrMath.h:294
saga::core::fract
float fract(float x)
Definition: irrMath.h:794
saga::core::RECIPROCAL_PI64
const double RECIPROCAL_PI64
Constant for 64bit reciprocal of PI.
Definition: irrMath.h:51
saga::core::reciprocal_approxim
REALINLINE float reciprocal_approxim(const float f)
Definition: irrMath.h:651
saga::core::inttofloat::f
float f
Definition: irrMath.h:413
REALINLINE
#define REALINLINE
Definition: irrMath.h:475
saga::core::inttofloat::s
std::int32_t s
Definition: irrMath.h:413
saga::core::IR
std::uint32_t IR(float x)
Definition: irrMath.h:429
saga::core::floor32
REALINLINE std::int32_t floor32(float x)
Definition: irrMath.h:692
saga::core::abs_
T abs_(const T &a)
returns abs of two values. Own implementation to get rid of STL (VS6 problems)
Definition: irrMath.h:191
saga::core::DEGTORAD
const float DEGTORAD
32bit Constant for converting from degrees to radians
Definition: irrMath.h:54
saga::core::RADTODEG64
const double RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:63
saga::core::s32_max
std::int32_t s32_max(std::int32_t a, std::int32_t b)
Definition: irrMath.h:389
saga::core::getHorizontalAngle
glm::vec3 getHorizontalAngle(const glm::vec3 &vec)
Definition: irrMath.h:71
saga::core::round32
REALINLINE std::int32_t round32(float x)
Definition: irrMath.h:757
saga::core::relativeErrorFactor
T relativeErrorFactor()
Definition: irrMath.h:266
saga::core::squareroot
REALINLINE float squareroot(const float f)
Definition: irrMath.h:545
saga::core::FloatIntUnion32
Definition: irrMath.h:305
saga::core::reciprocal_squareroot
REALINLINE double reciprocal_squareroot(const double x)
Definition: irrMath.h:571
saga::core::PI64
const double PI64
Constant for 64bit PI.
Definition: irrMath.h:48
saga::core::s32_clamp
std::int32_t s32_clamp(std::int32_t value, std::int32_t low, std::int32_t high)
Definition: irrMath.h:395
saga::core::isnotzero
bool isnotzero(const float a, const float tolerance=ROUNDING_ERROR_float)
returns if a equals not zero, taking rounding errors into account
Definition: irrMath.h:358
saga::core::if_c_a_else_b
REALINLINE std::uint32_t if_c_a_else_b(const std::int32_t condition, const std::uint32_t a, const std::uint32_t b)
conditional set based on mask and arithmetic shift
Definition: irrMath.h:497
saga::core::if_c_a_else_0
REALINLINE std::uint32_t if_c_a_else_0(const std::int32_t condition, const std::uint32_t a)
conditional set based on mask and arithmetic shift
Definition: irrMath.h:509
saga::core::equals
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:285
saga::core::ceil32
REALINLINE std::int32_t ceil32(float x)
Definition: irrMath.h:724
saga::core::clearFPUException
REALINLINE void clearFPUException()
Definition: irrMath.h:530
saga::core::isBetweenPoints
bool isBetweenPoints(const glm::vec3 &point, const glm::vec3 &begin, const glm::vec3 &end)
Definition: irrMath.h:65
saga::core::ROUNDING_ERROR_float
const float ROUNDING_ERROR_float
Definition: irrMath.h:29
saga::core::reciprocal
REALINLINE float reciprocal(const float f)
Definition: irrMath.h:609
saga::core::inttofloat
Definition: irrMath.h:413
saga::core::inttofloat::u
std::uint32_t u
Definition: irrMath.h:413
saga::core::ROUNDING_ERROR_S32
const std::int32_t ROUNDING_ERROR_S32
Rounding error constant often used when comparing float values.
Definition: irrMath.h:24
saga::core::float_max3
float float_max3(const float a, const float b, const float c)
Definition: irrMath.h:784
saga::core::ROUNDING_ERROR_double
const double ROUNDING_ERROR_double
Definition: irrMath.h:30
saga::core::degToRad
float degToRad(float degrees)
Utility function to convert a degrees value to radians.
Definition: irrMath.h:147
saga::core::lerp
T lerp(const T &a, const T &b, const float t)
Definition: irrMath.h:199
saga::core::float_min3
float float_min3(const float a, const float b, const float c)
Definition: irrMath.h:789
saga::core::DEGTORAD64
const double DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:60
saga::core::setbit_cond
REALINLINE void setbit_cond(std::uint32_t &state, std::int32_t condition, std::uint32_t mask)
Definition: irrMath.h:518
saga::core::max_
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:177
saga::core::HALF_PI
const float HALF_PI
Constant for half of PI.
Definition: irrMath.h:42
saga::core::equalsByUlp
bool equalsByUlp(float a, float b, int maxUlpDiff)
We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exi...
Definition: irrMath.h:317
saga::core::FloatIntUnion32::FloatIntUnion32
FloatIntUnion32(float f1=0.0f)
Definition: irrMath.h:307
saga::core::iszero
bool iszero(const double a, const double tolerance=ROUNDING_ERROR_double)
returns if a equals zero, taking rounding errors into account
Definition: irrMath.h:346
saga::core::radToDeg
float radToDeg(float radians)
Utility function to convert a radian value to degrees.
Definition: irrMath.h:129
saga::core::RECIPROCAL_PI
const float RECIPROCAL_PI
Constant for reciprocal of PI.
Definition: irrMath.h:39
saga::core::rotationToDirection
glm::vec3 rotationToDirection(const glm::vec3 &vec, const glm::vec3 &forwards={0, 0, 1})
Definition: irrMath.h:95
saga::core::min_
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:163
saga::core::RADTODEG
const float RADTODEG
32bit constant for converting from radians to degrees (formally known as GRAD_PI)
Definition: irrMath.h:57
saga::core::FR
float FR(std::uint32_t x)
Floating-point representation of an integer value.
Definition: irrMath.h:439
saga::core::s32_min
std::int32_t s32_min(std::int32_t a, std::int32_t b)
Definition: irrMath.h:383
saga::core::round_
float round_(float x)
Definition: irrMath.h:525
saga
Definition: aabbox3d.h:11
saga::core::clamp
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:206
saga::core::FloatIntUnion32::i
std::int32_t i
Definition: irrMath.h:311
saga::core::FloatIntUnion32::f
float f
Definition: irrMath.h:312
saga::core::PI
const float PI
Constant for PI.
Definition: irrMath.h:36
saga::core::FloatIntUnion32::sign
bool sign() const
Definition: irrMath.h:309
saga::core::roundingError
T roundingError()
Definition: irrMath.h:228
saga::core::swap
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition: irrMath.h:217