OpenVDB  2.3.0
Math.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
34 
35 #ifndef OPENVDB_MATH_HAS_BEEN_INCLUDED
36 #define OPENVDB_MATH_HAS_BEEN_INCLUDED
37 
38 #include <assert.h>
39 #include <algorithm> // for std::max()
40 #include <cmath> // for floor(), ceil() and sqrt()
41 #include <math.h> // for pow(), fabs() etc
42 #include <cstdlib> // for srand(), abs(int)
43 #include <limits> // for std::numeric_limits<Type>::max()
44 #include <string>
45 #include <boost/numeric/conversion/conversion_traits.hpp>
46 #include <boost/math/special_functions/cbrt.hpp>
47 #include <boost/random/mersenne_twister.hpp> // for boost::random::mt19937
48 #include <boost/random/uniform_01.hpp>
49 #include <boost/random/uniform_int.hpp>
50 #include <boost/version.hpp> // for BOOST_VERSION
51 #include <openvdb/Platform.h>
52 #include <openvdb/version.h>
53 
54 
55 // Compile pragmas
56 
57 // Intel(r) compiler fires remark #1572: floating-point equality and inequality
58 // comparisons are unrealiable when == or != is used with floating point operands.
59 #if defined(__INTEL_COMPILER)
60  #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN \
61  _Pragma("warning (push)") \
62  _Pragma("warning (disable:1572)")
63  #define OPENVDB_NO_FP_EQUALITY_WARNING_END \
64  _Pragma("warning (pop)")
65 #else
66  // For GCC, #pragma GCC diagnostic ignored "-Wfloat-equal"
67  // isn't working until gcc 4.2+,
68  // Trying
69  // #pragma GCC system_header
70  // creates other problems, most notably "warning: will never be executed"
71  // in from templates, unsure of how to work around.
72  // If necessary, could use integer based comparisons for equality
73  #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
74  #define OPENVDB_NO_FP_EQUALITY_WARNING_END
75 #endif
76 
77 namespace openvdb {
79 namespace OPENVDB_VERSION_NAME {
80 
85 template<typename T> inline T zeroVal() { return T(0); }
87 template<> inline std::string zeroVal<std::string>() { return ""; }
89 template<> inline bool zeroVal<bool>() { return false; }
90 
92 
93 inline std::string operator+(const std::string& s, bool) { return s; }
96 inline std::string operator+(const std::string& s, int) { return s; }
97 inline std::string operator+(const std::string& s, float) { return s; }
98 inline std::string operator+(const std::string& s, double) { return s; }
100 
101 
102 namespace math {
103 
107 template<typename T> inline T negative(const T& val) { return T(-val); }
109 template<> inline bool negative(const bool& val) { return !val; }
111 template<> inline std::string negative(const std::string& val) { return val; }
112 
113 
115 template<typename T> struct Tolerance { static T value() { return zeroVal<T>(); } };
117 template<> struct Tolerance<float> { static float value() { return 1e-8f; } };
118 template<> struct Tolerance<double> { static double value() { return 1e-15; } };
120 
122 template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
124 template<> struct Delta<float> { static float value() { return 1e-5f; } };
125 template<> struct Delta<double> { static double value() { return 1e-9; } };
127 
128 
129 // ==========> Random Values <==================
130 
133 template<typename FloatType = double, typename EngineType = boost::mt19937>
134 class Rand01
135 {
136 private:
137  EngineType mEngine;
138  boost::uniform_01<FloatType> mRand;
139 
140 public:
141  typedef FloatType ValueType;
142 
145  Rand01(unsigned int seed): mEngine(static_cast<typename EngineType::result_type>(seed)) {}
146 
148  FloatType operator()() { return mRand(mEngine); }
149 };
150 
152 
153 
156 template<typename EngineType = boost::mt19937>
157 class RandInt
158 {
159 private:
160 #if BOOST_VERSION >= 104700
161  typedef boost::random::uniform_int_distribution<int> Distr;
162 #else
163  typedef boost::uniform_int<int> Distr;
164 #endif
165  EngineType mEngine;
166  Distr mRand;
167 
168 public:
172  RandInt(unsigned int seed, int imin, int imax):
173  mEngine(static_cast<typename EngineType::result_type>(seed)),
174  mRand(std::min(imin, imax), std::max(imin, imax))
175  {}
176 
178  void setRange(int imin, int imax) { mRand = Distr(std::min(imin, imax), std::max(imin, imax)); }
179 
181  int operator()() { return mRand(mEngine); }
184  int operator()(int imin, int imax)
185  {
186  const int lo = std::min(imin, imax), hi = std::max(imin, imax);
187 #if BOOST_VERSION >= 104700
188  return mRand(mEngine, Distr::param_type(lo, hi));
189 #else
190  return Distr(lo, hi)(mEngine);
191 #endif
192  }
193 };
194 
196 
197 
198 // ==========> Clamp <==================
199 
201 template<typename Type>
202 inline Type
203 Clamp(Type x, Type min, Type max)
204 {
205  assert(min<max);
206  return x > min ? x < max ? x : max : min;
207 }
208 
209 
211 template<typename Type>
212 inline Type
213 Clamp01(Type x) { return x > Type(0) ? x < Type(1) ? x : Type(1) : Type(0); }
214 
215 
217 template<typename Type>
218 inline bool
219 ClampTest01(Type &x)
220 {
221  if (x >= Type(0) && x <= Type(1)) return false;
222  x = x < Type(0) ? Type(0) : Type(1);
223  return true;
224 }
225 
226 
229 template<typename Type>
230 inline Type
231 SmoothUnitStep(Type x, Type min, Type max)
232 {
233  assert(min < max);
234  const Type t = (x-min)/(max-min);
235  return t > 0 ? t < 1 ? (3-2*t)*t*t : Type(1) : Type(0);
236 }
237 
238 
239 // ==========> Absolute Value <==================
240 
241 
243 inline int32_t Abs(int32_t i) { return abs(i); }
245 inline int64_t Abs(int64_t i)
246 {
247 #ifdef _MSC_VER
248  return (i < int64_t(0) ? -i : i);
249 #else
250  return labs(i);
251 #endif
252 }
253 inline float Abs(float x) { return fabs(x); }
254 inline double Abs(double x) { return fabs(x); }
255 inline long double Abs(long double x) { return fabsl(x); }
256 inline uint32_t Abs(uint32_t i) { return i; }
257 inline uint64_t Abs(uint64_t i) { return i; }
258 // On OSX size_t and uint64_t are different types
259 #if defined(__APPLE__) || defined(MACOSX)
260 inline size_t Abs(size_t i) { return i; }
261 #endif
262 
263 
264 
266 
267 
268 // ==========> Value Comparison <==================
269 
270 
272 template<typename Type>
273 inline bool
274 isZero(const Type& x)
275 {
277  return x == zeroVal<Type>();
279 }
280 
281 
284 template<typename Type>
285 inline bool
286 isApproxZero(const Type& x)
287 {
288  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
289  return x < tolerance && x > -tolerance;
290 }
291 
293 template<typename Type>
294 inline bool
295 isApproxZero(const Type& x, const Type& tolerance)
296 {
297  return x < tolerance && x > -tolerance;
298 }
299 
300 
302 template<typename Type>
303 inline bool
304 isNegative(const Type& x) { return x < zeroVal<Type>(); }
305 
307 template<> inline bool isNegative<bool>(const bool&) { return false; }
308 
309 
312 template<typename Type>
313 inline bool
314 isApproxEqual(const Type& a, const Type& b)
315 {
316  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
317  return !(Abs(a - b) > tolerance);
318 }
319 
320 
322 template<typename Type>
323 inline bool
324 isApproxEqual(const Type& a, const Type& b, const Type& tolerance)
325 {
326  return !(Abs(a - b) > tolerance);
327 }
328 
329 #define OPENVDB_EXACT_IS_APPROX_EQUAL(T) \
330  template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
331  template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
332 
333 
336 
337 
340 template<typename Type>
341 inline bool
342 isApproxLarger(const Type& a, const Type& b, const Type& tolerance)
343 {
344  return (b - a < tolerance);
345 }
346 
347 
349 template<typename T0, typename T1>
350 inline bool
351 isExactlyEqual(const T0& a, const T1& b)
352 {
354  return a == b;
356 }
357 
358 
359 template<typename Type>
360 inline bool
361 isRelOrApproxEqual(const Type& a, const Type& b, const Type& absTol, const Type& relTol)
362 {
363  // First check to see if we are inside the absolute tolerance
364  // Necessary for numbers close to 0
365  if (!(Abs(a - b) > absTol)) return true;
366 
367  // Next check to see if we are inside the relative tolerance
368  // to handle large numbers that aren't within the abs tolerance
369  // but could be the closest floating point representation
370  double relError;
371  if (Abs(b) > Abs(a)) {
372  relError = Abs((a - b) / b);
373  } else {
374  relError = Abs((a - b) / a);
375  }
376  return (relError <= relTol);
377 }
378 
379 template<>
380 inline bool
381 isRelOrApproxEqual(const bool& a, const bool& b, const bool&, const bool&)
382 {
383  return (a == b);
384 }
385 
386 
387 // Avoid strict aliasing issues by using type punning
388 // http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
389 // Using "casting through a union(2)"
390 inline int32_t
391 floatToInt32(const float aFloatValue)
392 {
393  union FloatOrInt32 { float floatValue; int32_t int32Value; };
394  const FloatOrInt32* foi = reinterpret_cast<const FloatOrInt32*>(&aFloatValue);
395  return foi->int32Value;
396 }
397 
398 
399 inline int64_t
400 doubleToInt64(const double aDoubleValue)
401 {
402  union DoubleOrInt64 { double doubleValue; int64_t int64Value; };
403  const DoubleOrInt64* dol = reinterpret_cast<const DoubleOrInt64*>(&aDoubleValue);
404  return dol->int64Value;
405 }
406 
407 
408 // aUnitsInLastPlace is the allowed difference between the least significant digits
409 // of the numbers' floating point representation
410 // Please read refernce paper before trying to use isUlpsEqual
411 // http://www.cygnus-software.com/papers/comparingFloats/comparingFloats.htm
412 inline bool
413 isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
414 {
415  int64_t longLeft = doubleToInt64(aLeft);
416  // Because of 2's complement, must restore lexicographical order
417  if (longLeft < 0) {
418  longLeft = INT64_C(0x8000000000000000) - longLeft;
419  }
420 
421  int64_t longRight = doubleToInt64(aRight);
422  // Because of 2's complement, must restore lexicographical order
423  if (longRight < 0) {
424  longRight = INT64_C(0x8000000000000000) - longRight;
425  }
426 
427  int64_t difference = labs(longLeft - longRight);
428  return (difference <= aUnitsInLastPlace);
429 }
430 
431 inline bool
432 isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
433 {
434  int32_t intLeft = floatToInt32(aLeft);
435  // Because of 2's complement, must restore lexicographical order
436  if (intLeft < 0) {
437  intLeft = 0x80000000 - intLeft;
438  }
439 
440  int32_t intRight = floatToInt32(aRight);
441  // Because of 2's complement, must restore lexicographical order
442  if (intRight < 0) {
443  intRight = 0x80000000 - intRight;
444  }
445 
446  int32_t difference = abs(intLeft - intRight);
447  return (difference <= aUnitsInLastPlace);
448 }
449 
450 
452 
453 
454 // ==========> Pow <==================
455 
457 template<typename Type>
458 inline Type Pow2(Type x) { return x*x; }
459 
461 template<typename Type>
462 inline Type Pow3(Type x) { return x*x*x; }
463 
465 template<typename Type>
466 inline Type Pow4(Type x) { return Pow2(Pow2(x)); }
467 
469 template<typename Type>
470 Type
471 Pow(Type x, int n)
472 {
473  Type ans = 1;
474  if (n < 0) {
475  n = -n;
476  x = Type(1)/x;
477  }
478  while (n--) ans *= x;
479  return ans;
480 }
481 
483 inline float
485 Pow(float b, float e)
486 {
487  assert( b >= 0.0f && "Pow(float,float): base is negative" );
488  return powf(b,e);
489 }
490 
491 inline double
492 Pow(double b, double e)
493 {
494  assert( b >= 0.0 && "Pow(double,double): base is negative" );
495  return pow(b,e);
496 }
498 
499 
500 // ==========> Max <==================
501 
503 template<typename Type>
504 inline const Type&
505 Max(const Type& a, const Type& b)
506 {
507  return std::max(a,b) ;
508 }
509 
511 template<typename Type>
512 inline const Type&
513 Max(const Type& a, const Type& b, const Type& c)
514 {
515  return std::max( std::max(a,b), c ) ;
516 }
517 
519 template<typename Type>
520 inline const Type&
521 Max(const Type& a, const Type& b, const Type& c, const Type& d)
522 {
523  return std::max(std::max(a,b), std::max(c,d));
524 }
525 
527 template<typename Type>
528 inline const Type&
529 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
530 {
531  return std::max(std::max(a,b), Max(c,d,e));
532 }
533 
535 template<typename Type>
536 inline const Type&
537 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
538 {
539  return std::max(Max(a,b,c), Max(d,e,f));
540 }
541 
543 template<typename Type>
544 inline const Type&
545 Max(const Type& a, const Type& b, const Type& c, const Type& d,
546  const Type& e, const Type& f, const Type& g)
547 {
548  return std::max(Max(a,b,c,d), Max(e,f,g));
549 }
550 
552 template<typename Type>
553 inline const Type&
554 Max(const Type& a, const Type& b, const Type& c, const Type& d,
555  const Type& e, const Type& f, const Type& g, const Type& h)
556 {
557  return std::max(Max(a,b,c,d), Max(e,f,g,h));
558 }
559 
560 
561 // ==========> Min <==================
562 
564 template<typename Type>
565 inline const Type&
566 Min(const Type& a, const Type& b) { return std::min(a, b); }
567 
569 template<typename Type>
570 inline const Type&
571 Min(const Type& a, const Type& b, const Type& c) { return std::min(std::min(a, b), c); }
572 
574 template<typename Type>
575 inline const Type&
576 Min(const Type& a, const Type& b, const Type& c, const Type& d)
577 {
578  return std::min(std::min(a, b), std::min(c, d));
579 }
580 
582 template<typename Type>
583 inline const Type&
584 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
585 {
586  return std::min(std::min(a,b), Min(c,d,e));
587 }
588 
590 template<typename Type>
591 inline const Type&
592 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
593 {
594  return std::min(Min(a,b,c), Min(d,e,f));
595 }
596 
598 template<typename Type>
599 inline const Type&
600 Min(const Type& a, const Type& b, const Type& c, const Type& d,
601  const Type& e, const Type& f, const Type& g)
602 {
603  return std::min(Min(a,b,c,d), Min(e,f,g));
604 }
605 
607 template<typename Type>
608 inline const Type&
609 Min(const Type& a, const Type& b, const Type& c, const Type& d,
610  const Type& e, const Type& f, const Type& g, const Type& h)
611 {
612  return std::min(Min(a,b,c,d), Min(e,f,g,h));
613 }
614 
615 
616 // ============> Exp <==================
617 
619 template<typename Type>
620 inline Type Exp(const Type& x) { return std::exp(x); }
621 
622 
624 
625 
627 template <typename Type>
628 inline int Sign(const Type &x) { return (zeroVal<Type>() < x) - (x < zeroVal<Type>()); }
629 
630 
633 template <typename Type>
634 inline bool
635 SignChange(const Type& a, const Type& b)
636 {
637  return ( (a<zeroVal<Type>()) ^ (b<zeroVal<Type>()) );
638 }
639 
640 
643 template <typename Type>
644 inline bool
645 ZeroCrossing(const Type& a, const Type& b)
646 {
647  return a * b <= zeroVal<Type>();
648 }
649 
650 
652 inline float Sqrt(float x) { return sqrtf(x); }
654 inline double Sqrt(double x) { return sqrt(x); }
655 inline long double Sqrt(long double x) { return sqrtl(x); }
657 
658 
660 inline float Cbrt(float x) { return boost::math::cbrt(x); }
662 inline double Cbrt(double x) { return boost::math::cbrt(x); }
663 inline long double Cbrt(long double x) { return boost::math::cbrt(x); }
665 
666 
668 inline int Mod(int x, int y) { return (x % y); }
670 inline float Mod(float x, float y) { return fmodf(x,y); }
671 inline double Mod(double x, double y) { return fmod(x,y); }
672 inline long double Mod(long double x, long double y) { return fmodl(x,y); }
673 template<typename Type> inline Type Remainder(Type x, Type y) { return Mod(x,y); }
675 
676 
678 inline float RoundUp(float x) { return ceilf(x); }
680 inline double RoundUp(double x) { return ceil(x); }
681 inline long double RoundUp(long double x) { return ceill(x); }
683 template<typename Type>
685 inline Type
686 RoundUp(Type x, Type base)
687 {
688  Type remainder = Remainder(x, base);
689  return remainder ? x-remainder+base : x;
690 }
691 
692 
694 inline float RoundDown(float x) { return floorf(x); }
696 inline double RoundDown(double x) { return floor(x); }
697 inline long double RoundDown(long double x) { return floorl(x); }
698 template <typename Type> inline Type Round(Type x) { return RoundDown(x+0.5); }
700 template<typename Type>
702 inline Type
703 RoundDown(Type x, Type base)
704 {
705  Type remainder = Remainder(x, base);
706  return remainder ? x-remainder : x;
707 }
708 
709 
711 template<typename Type>
712 inline Type
713 IntegerPart(Type x)
714 {
715  return (x > 0 ? RoundDown(x) : RoundUp(x));
716 }
717 
719 template<typename Type>
720 inline Type FractionalPart(Type x) { return Mod(x,Type(1)); }
721 
722 
724 inline int Floor(float x) { return (int)RoundDown(x); }
726 inline int Floor(double x) { return (int)RoundDown(x); }
727 inline int Floor(long double x) { return (int)RoundDown(x); }
729 
730 
732 inline int Ceil(float x) { return (int)RoundUp(x); }
734 inline int Ceil(double x) { return (int)RoundUp(x); }
735 inline int Ceil(long double x) { return (int)RoundUp(x); }
737 
738 
740 template<typename Type>
741 inline Type Chop(Type x, Type delta) { return (Abs(x) < delta ? zeroVal<Type>() : x); }
742 
743 
745 template<typename Type>
746 inline Type
747 Truncate(Type x, unsigned int digits)
748 {
749  Type tenth = Pow(10,digits);
750  return RoundDown(x*tenth+0.5)/tenth;
751 }
752 
753 
755 
756 
758 template<typename Type>
759 inline Type
760 Inv(Type x)
761 {
762  assert(x);
763  return Type(1)/x;
764 }
765 
766 
767 enum Axis {
768  X_AXIS = 0,
769  Y_AXIS = 1,
770  Z_AXIS = 2
771 };
772 
773 // enum values are consistent with their historical mx analogs.
783 };
784 
785 
786 template <typename S, typename T>
787 struct promote {
788  typedef typename boost::numeric::conversion_traits<S, T>::supertype type;
789 };
790 
791 
799 template<typename Vec3T>
800 size_t
801 MinIndex(const Vec3T& v)
802 {
803  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
804  const size_t hashKey =
805  ((v[0] < v[1]) << 2) + ((v[0] < v[2]) << 1) + (v[1] < v[2]);// ?*4+?*2+?*1
806  return hashTable[hashKey];
807 }
808 
809 
817 template<typename Vec3T>
818 size_t
819 MaxIndex(const Vec3T& v)
820 {
821  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
822  const size_t hashKey =
823  ((v[0] > v[1]) << 2) + ((v[0] > v[2]) << 1) + (v[1] > v[2]);// ?*4+?*2+?*1
824  return hashTable[hashKey];
825 }
826 
827 } // namespace math
828 } // namespace OPENVDB_VERSION_NAME
829 } // namespace openvdb
830 
831 #endif // OPENVDB_MATH_MATH_HAS_BEEN_INCLUDED
832 
833 // Copyright (c) 2012-2013 DreamWorks Animation LLC
834 // All rights reserved. This software is distributed under the
835 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Type Round(Type x)
Return x rounded down to the nearest integer.
Definition: Math.h:698
int operator()()
Return a randomly-generated integer in the current range.
Definition: Math.h:181
Type Exp(const Type &x)
Return .
Definition: Math.h:620
bool isApproxLarger(const Type &a, const Type &b, const Type &tolerance)
Return true if a is larger than b to within the given tolerance, i.e., if b - a < tolerance...
Definition: Math.h:342
uint64_t Abs(uint64_t i)
Return the absolute value of the given quantity.
Definition: Math.h:257
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:85
bool isRelOrApproxEqual(const bool &a, const bool &b, const bool &, const bool &)
Definition: Math.h:381
bool ZeroCrossing(const Type &a, const Type &b)
Return true if the interval [a, b] includes zero, i.e., if either a or b is zero or if they have diff...
Definition: Math.h:645
int operator()(int imin, int imax)
Return a randomly-generated integer in the new range [imin, imax], without changing the current range...
Definition: Math.h:184
static float value()
Definition: Math.h:117
std::string negative(const std::string &val)
Return the "negation" of the given string.
Definition: Math.h:111
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:324
Rand01< double, boost::mt19937 > Random01
Definition: Math.h:151
int32_t floatToInt32(const float aFloatValue)
Definition: Math.h:391
Simple random integer generator.
Definition: Math.h:157
long double Cbrt(long double x)
Return the cube root of a floating-point value.
Definition: Math.h:663
FloatType ValueType
Definition: Math.h:141
Definition: Math.h:769
Type Pow2(Type x)
Return .
Definition: Math.h:458
Delta for small floating-point offsets.
Definition: Math.h:123
int64_t doubleToInt64(const double aDoubleValue)
Definition: Math.h:400
bool ClampTest01(Type &x)
Return true if x is outside [0,1].
Definition: Math.h:219
bool isNegative< bool >(const bool &)
Return false, since bool values are never less than zero.
Definition: Math.h:307
bool isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
Definition: Math.h:432
Definition: Math.h:768
long double Sqrt(long double x)
Return the square root of a floating-point value.
Definition: Math.h:655
Type RoundDown(Type x, Type base)
Return x rounded down to the nearest multiple of base.
Definition: Math.h:703
Type RoundUp(Type x, Type base)
Return x rounded up to the nearest multiple of base.
Definition: Math.h:686
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:819
Type Chop(Type x, Type delta)
Return x if it is greater in magnitude than delta. Otherwise, return zero.
Definition: Math.h:741
Type SmoothUnitStep(Type x, Type min, Type max)
Return 0 if x < min, 1 if x > max or else , where .
Definition: Math.h:231
#define OPENVDB_VERSION_NAME
Definition: version.h:45
int Floor(long double x)
Return the floor of x.
Definition: Math.h:727
RotationOrder
Definition: Math.h:774
const Type & Min(const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g, const Type &h)
Return the minimum of eight values.
Definition: Math.h:609
static double value()
Definition: Math.h:118
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:801
bool SignChange(const Type &a, const Type &b)
Return true if a and b have different signs.
Definition: Math.h:635
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:351
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:134
int Sign(const Type &x)
Return the sign of the given value as an integer (either -1, 0 or 1).
Definition: Math.h:628
Type FractionalPart(Type x)
Return the fractional part of x.
Definition: Math.h:720
int Ceil(long double x)
Return the ceiling of x.
Definition: Math.h:735
void setRange(int imin, int imax)
Change the range over which integers are distributed to [imin, imax].
Definition: Math.h:178
Definition: Math.h:787
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
Definition: Math.h:74
long double Mod(long double x, long double y)
Return the remainder of x / y.
Definition: Math.h:672
Type Pow3(Type x)
Return .
Definition: Math.h:462
RandInt(unsigned int seed, int imin, int imax)
Initialize the generator.
Definition: Math.h:172
Type Truncate(Type x, unsigned int digits)
Return x truncated to the given number of decimal digits.
Definition: Math.h:747
double Pow(double b, double e)
Return .
Definition: Math.h:492
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
Definition: Math.h:73
Rand01(unsigned int seed)
Initialize the generator.
Definition: Math.h:145
boost::numeric::conversion_traits< S, T >::supertype type
Definition: Math.h:788
static float value()
Definition: Math.h:124
const Type & Max(const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g, const Type &h)
Return the maximum of eight values.
Definition: Math.h:554
Type Remainder(Type x, Type y)
Return the remainder of x / y.
Definition: Math.h:673
Type Clamp(Type x, Type min, Type max)
Return x clamped to [min, max].
Definition: Math.h:203
Type Pow4(Type x)
Return .
Definition: Math.h:466
Type Clamp01(Type x)
Return x clamped to [0, 1].
Definition: Math.h:213
Axis
Definition: Math.h:767
Type Inv(Type x)
Return the inverse of x.
Definition: Math.h:760
static double value()
Definition: Math.h:125
Definition: Math.h:770
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:304
bool zeroVal< bool >()
Return the bool value that corresponds to zero.
Definition: Math.h:89
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:274
Tolerance for floating-point comparison.
Definition: Math.h:116
Type IntegerPart(Type x)
Return the integer part of x.
Definition: Math.h:713
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
Definition: Math.h:329
bool isApproxZero(const Type &x, const Type &tolerance)
Return true if x is equal to zero to within the given tolerance.
Definition: Math.h:295
FloatType operator()()
Return a uniformly distributed random number in the range [0, 1).
Definition: Math.h:148
RandInt< boost::mt19937 > RandomInt
Definition: Math.h:195
std::string operator+(const std::string &s, double)
Needed to support the (zeroVal() + val) idiom when ValueType is std::string.
Definition: Math.h:98