HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Math.h File Reference

General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at least arbitrary numeric value types) More...

#include <assert.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <limits>
#include <string>
#include <hboost/numeric/conversion/conversion_traits.hpp>
#include <hboost/math/special_functions/cbrt.hpp>
#include <hboost/math/special_functions/fpclassify.hpp>
#include <hboost/random/mersenne_twister.hpp>
#include <hboost/random/uniform_01.hpp>
#include <hboost/random/uniform_int.hpp>
#include <hboost/version.hpp>
#include <openvdb/Platform.h>
#include <openvdb/version.h>
+ Include dependency graph for Math.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  openvdb::OPENVDB_VERSION_NAME::math::Tolerance< T >
 Tolerance for floating-point comparison. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::math::Tolerance< float >
 
struct  openvdb::OPENVDB_VERSION_NAME::math::Tolerance< double >
 
struct  openvdb::OPENVDB_VERSION_NAME::math::Delta< T >
 Delta for small floating-point offsets. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::math::Delta< float >
 
struct  openvdb::OPENVDB_VERSION_NAME::math::Delta< double >
 
class  openvdb::OPENVDB_VERSION_NAME::math::Rand01< FloatType, EngineType >
 Simple generator of random numbers over the range [0, 1) More...
 
class  openvdb::OPENVDB_VERSION_NAME::math::RandInt< IntType, EngineType >
 Simple random integer generator. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::math::promote< S, T >
 

Namespaces

 openvdb
 
 openvdb::OPENVDB_VERSION_NAME
 
 openvdb::OPENVDB_VERSION_NAME::math
 

Macros

#define PRAGMA(x)   _Pragma(#x)
 
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
 
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
 
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
 

Typedefs

typedef Rand01< double,
hboost::mt19937 > 
openvdb::OPENVDB_VERSION_NAME::math::Random01
 
typedef RandInt< int,
hboost::mt19937 > 
openvdb::OPENVDB_VERSION_NAME::math::RandomInt
 

Enumerations

enum  openvdb::OPENVDB_VERSION_NAME::math::Axis { openvdb::OPENVDB_VERSION_NAME::math::X_AXIS = 0, openvdb::OPENVDB_VERSION_NAME::math::Y_AXIS = 1, openvdb::OPENVDB_VERSION_NAME::math::Z_AXIS = 2 }
 
enum  openvdb::OPENVDB_VERSION_NAME::math::RotationOrder {
  openvdb::OPENVDB_VERSION_NAME::math::XYZ_ROTATION = 0, openvdb::OPENVDB_VERSION_NAME::math::XZY_ROTATION, openvdb::OPENVDB_VERSION_NAME::math::YXZ_ROTATION, openvdb::OPENVDB_VERSION_NAME::math::YZX_ROTATION,
  openvdb::OPENVDB_VERSION_NAME::math::ZXY_ROTATION, openvdb::OPENVDB_VERSION_NAME::math::ZYX_ROTATION, openvdb::OPENVDB_VERSION_NAME::math::XZX_ROTATION, openvdb::OPENVDB_VERSION_NAME::math::ZXZ_ROTATION
}
 

Functions

template<typename T >
openvdb::OPENVDB_VERSION_NAME::zeroVal ()
 Return the value of type T that corresponds to zero. More...
 
template<>
std::string openvdb::OPENVDB_VERSION_NAME::zeroVal< std::string > ()
 Return the std::string value that corresponds to zero. More...
 
template<>
bool openvdb::OPENVDB_VERSION_NAME::zeroVal< bool > ()
 Return the bool value that corresponds to zero. More...
 
template<typename T >
openvdb::OPENVDB_VERSION_NAME::math::negative (const T &val)
 Return the unary negation of the given value. More...
 
template<>
bool openvdb::OPENVDB_VERSION_NAME::math::negative (const bool &val)
 Return the negation of the given boolean. More...
 
template<>
std::string openvdb::OPENVDB_VERSION_NAME::math::negative (const std::string &val)
 Return the "negation" of the given string. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Clamp (Type x, Type min, Type max)
 Return x clamped to [min, max]. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Clamp01 (Type x)
 Return x clamped to [0, 1]. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::ClampTest01 (Type &x)
 Return true if x is outside [0,1]. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::SmoothUnitStep (Type x)
 Return 0 if x < 0, 1 if x > 1 or else $(3-2x)x^2$. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::SmoothUnitStep (Type x, Type min, Type max)
 Return 0 if x < min, 1 if x > max or else $(3-2t)t^2$, where $t = (x-min)/(max-min)$. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isZero (const Type &x)
 Return true if x is exactly equal to zero. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isApproxZero (const Type &x)
 Return true if x is equal to zero to within the default floating-point comparison tolerance. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isApproxZero (const Type &x, const Type &tolerance)
 Return true if x is equal to zero to within the given tolerance. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isNegative (const Type &x)
 Return true if x is less than zero. More...
 
template<>
bool openvdb::OPENVDB_VERSION_NAME::math::isNegative< bool > (const bool &)
 Return false, since bool values are never less than zero. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isFinite (const Type &x)
 Return true if x is finite. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isApproxEqual (const Type &a, const Type &b)
 Return true if a is equal to b to within the default floating-point comparison tolerance. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isApproxEqual (const Type &a, const Type &b, const Type &tolerance)
 Return true if a is equal to b to within the given tolerance. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::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. More...
 
template<typename T0 , typename T1 >
bool openvdb::OPENVDB_VERSION_NAME::math::isExactlyEqual (const T0 &a, const T1 &b)
 Return true if a is exactly equal to b. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::isRelOrApproxEqual (const Type &a, const Type &b, const Type &absTol, const Type &relTol)
 
template<>
bool openvdb::OPENVDB_VERSION_NAME::math::isRelOrApproxEqual (const bool &a, const bool &b, const bool &, const bool &)
 
int32_t openvdb::OPENVDB_VERSION_NAME::math::floatToInt32 (const float aFloatValue)
 
int64_t openvdb::OPENVDB_VERSION_NAME::math::doubleToInt64 (const double aDoubleValue)
 
bool openvdb::OPENVDB_VERSION_NAME::math::isUlpsEqual (const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
 
bool openvdb::OPENVDB_VERSION_NAME::math::isUlpsEqual (const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow2 (Type x)
 Return $ x^2 $. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow3 (Type x)
 Return $ x^3 $. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow4 (Type x)
 Return $ x^4 $. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow (Type x, int n)
 Return $ x^n $. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b)
 Return the maximum of two values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b, const Type &c)
 Return the maximum of three values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b, const Type &c, const Type &d)
 Return the maximum of four values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e)
 Return the maximum of five values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f)
 Return the maximum of six values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g)
 Return the maximum of seven values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::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. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b)
 Return the minimum of two values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b, const Type &c)
 Return the minimum of three values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b, const Type &c, const Type &d)
 Return the minimum of four values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e)
 Return the minimum of five values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f)
 Return the minimum of six values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g)
 Return the minimum of seven values. More...
 
template<typename Type >
const Type & openvdb::OPENVDB_VERSION_NAME::math::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. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Exp (const Type &x)
 Return $ e^x $. More...
 
template<typename Type >
int openvdb::OPENVDB_VERSION_NAME::math::Sign (const Type &x)
 Return the sign of the given value as an integer (either -1, 0 or 1). More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::SignChange (const Type &a, const Type &b)
 Return true if a and b have different signs. More...
 
template<typename Type >
bool openvdb::OPENVDB_VERSION_NAME::math::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 different signs. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::RoundUp (Type x, Type base)
 Return x rounded up to the nearest multiple of base. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::RoundDown (Type x, Type base)
 Return x rounded down to the nearest multiple of base. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::EuclideanRemainder (Type x)
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::IntegerPart (Type x)
 Return the integer part of x. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::FractionalPart (Type x)
 Return the fractional part of x. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Chop (Type x, Type delta)
 Return x if it is greater or equal in magnitude than delta. Otherwise, return zero. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Truncate (Type x, unsigned int digits)
 Return x truncated to the given number of decimal digits. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Inv (Type x)
 Return the inverse of x. More...
 
template<typename Vec3T >
size_t openvdb::OPENVDB_VERSION_NAME::math::MinIndex (const Vec3T &v)
 Return the index [0,1,2] of the smallest value in a 3D vector. More...
 
template<typename Vec3T >
size_t openvdb::OPENVDB_VERSION_NAME::math::MaxIndex (const Vec3T &v)
 Return the index [0,1,2] of the largest value in a 3D vector. More...
 
std::string openvdb::OPENVDB_VERSION_NAME::operator+ (const std::string &s, bool)
 Needed to support the (zeroVal<ValueType>() + val) idiom when ValueType is std::string. More...
 
std::string openvdb::OPENVDB_VERSION_NAME::operator+ (const std::string &s, int)
 Needed to support the (zeroVal<ValueType>() + val) idiom when ValueType is std::string. More...
 
std::string openvdb::OPENVDB_VERSION_NAME::operator+ (const std::string &s, float)
 Needed to support the (zeroVal<ValueType>() + val) idiom when ValueType is std::string. More...
 
std::string openvdb::OPENVDB_VERSION_NAME::operator+ (const std::string &s, double)
 Needed to support the (zeroVal<ValueType>() + val) idiom when ValueType is std::string. More...
 
int32_t openvdb::OPENVDB_VERSION_NAME::math::Abs (int32_t i)
 Return the absolute value of the given quantity. More...
 
int64_t openvdb::OPENVDB_VERSION_NAME::math::Abs (int64_t i)
 Return the absolute value of the given quantity. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Abs (float x)
 Return the absolute value of the given quantity. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Abs (double x)
 Return the absolute value of the given quantity. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::Abs (long double x)
 Return the absolute value of the given quantity. More...
 
uint32_t openvdb::OPENVDB_VERSION_NAME::math::Abs (uint32_t i)
 Return the absolute value of the given quantity. More...
 
uint64_t openvdb::OPENVDB_VERSION_NAME::math::Abs (uint64_t i)
 Return the absolute value of the given quantity. More...
 
bool openvdb::OPENVDB_VERSION_NAME::math::Abs (bool b)
 Return the absolute value of the given quantity. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Pow (float b, float e)
 Return $ b^e $. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Pow (double b, double e)
 Return $ b^e $. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Sin (const float &x)
 Return $ sin(x) $. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Sin (const double &x)
 Return $ sin(x) $. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Cos (const float &x)
 Return $ cos(x) $. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Cos (const double &x)
 Return $ cos(x) $. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Sqrt (float x)
 Return the square root of a floating-point value. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Sqrt (double x)
 Return the square root of a floating-point value. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::Sqrt (long double x)
 Return the square root of a floating-point value. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Cbrt (float x)
 Return the cube root of a floating-point value. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Cbrt (double x)
 Return the cube root of a floating-point value. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::Cbrt (long double x)
 Return the cube root of a floating-point value. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Mod (int x, int y)
 Return the remainder of x / y. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Mod (float x, float y)
 Return the remainder of x / y. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Mod (double x, double y)
 Return the remainder of x / y. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::Mod (long double x, long double y)
 Return the remainder of x / y. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Remainder (Type x, Type y)
 Return the remainder of x / y. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::RoundUp (float x)
 Return x rounded up to the nearest integer. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::RoundUp (double x)
 Return x rounded up to the nearest integer. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::RoundUp (long double x)
 Return x rounded up to the nearest integer. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::RoundDown (float x)
 Return x rounded down to the nearest integer. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::RoundDown (double x)
 Return x rounded down to the nearest integer. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::RoundDown (long double x)
 Return x rounded down to the nearest integer. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Round (float x)
 Return x rounded to the nearest integer. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Round (double x)
 Return x rounded to the nearest integer. More...
 
long double openvdb::OPENVDB_VERSION_NAME::math::Round (long double x)
 Return x rounded to the nearest integer. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Floor (float x)
 Return the floor of x. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Floor (double x)
 Return the floor of x. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Floor (long double x)
 Return the floor of x. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Ceil (float x)
 Return the ceiling of x. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Ceil (double x)
 Return the ceiling of x. More...
 
int openvdb::OPENVDB_VERSION_NAME::math::Ceil (long double x)
 Return the ceiling of x. More...
 

Detailed Description

General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at least arbitrary numeric value types)

Definition in file Math.h.

Macro Definition Documentation

#define OPENVDB_EXACT_IS_APPROX_EQUAL (   T)
Value:
template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221

Definition at line 385 of file Math.h.

#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN

Definition at line 82 of file Math.h.

#define OPENVDB_NO_FP_EQUALITY_WARNING_END

Definition at line 83 of file Math.h.

#define PRAGMA (   x)    _Pragma(#x)

Definition at line 58 of file Math.h.