HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 <openvdb/Platform.h>
#include <openvdb/version.h>
#include <hboost/numeric/conversion/conversion_traits.hpp>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <random>
#include <string>
#include <type_traits>
+ 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 OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
 
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
 
#define OPENVDB_IS_POD(Type)
 
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
 

Typedefs

using openvdb::OPENVDB_VERSION_NAME::math::Random01 = Rand01< double, std::mt19937 >
 
using openvdb::OPENVDB_VERSION_NAME::math::RandomInt = RandInt< int, std::mt19937 >
 

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 >
constexpr 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<>
constexpr bool openvdb::OPENVDB_VERSION_NAME::zeroVal< bool > ()
 Return the bool value that corresponds to zero. More...
 
template<typename Type1 , typename Type2 >
auto openvdb::OPENVDB_VERSION_NAME::math::cwiseAdd (const Type1 &v, const Type2 s)
 Componentwise adder for POD types. More...
 
template<typename Type1 , typename Type2 >
bool openvdb::OPENVDB_VERSION_NAME::math::cwiseLessThan (const Type1 &a, const Type2 &b)
 Componentwise less than for POD types. More...
 
template<typename Type1 , typename Type2 >
bool openvdb::OPENVDB_VERSION_NAME::math::cwiseGreaterThan (const Type1 &a, const Type2 &b)
 Componentwise greater than for POD types. More...
 
template<typename T >
constexpr T openvdb::OPENVDB_VERSION_NAME::math::pi ()
 Pi constant taken from Boost to match old behaviour. More...
 
template<>
constexpr float openvdb::OPENVDB_VERSION_NAME::math::pi ()
 
template<>
constexpr double openvdb::OPENVDB_VERSION_NAME::math::pi ()
 
template<>
constexpr long double openvdb::OPENVDB_VERSION_NAME::math::pi ()
 
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 − 2 x) x . 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 − 2 t) t , where t = (xmin)/(maxmin). 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 &)
 
bool openvdb::OPENVDB_VERSION_NAME::math::isFinite (const float x)
 Return true if x is finite. More...
 
template<typename Type , typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool openvdb::OPENVDB_VERSION_NAME::math::isFinite (const Type &x)
 Return true if x is finite. More...
 
bool openvdb::OPENVDB_VERSION_NAME::math::isInfinite (const float x)
 Return true if x is an infinity value (either positive infinity or negative infinity). More...
 
template<typename Type , typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool openvdb::OPENVDB_VERSION_NAME::math::isInfinite (const Type &x)
 Return true if x is an infinity value (either positive infinity or negative infinity). More...
 
bool openvdb::OPENVDB_VERSION_NAME::math::isNan (const float x)
 Return true if x is a NaN (Not-A-Number) value. More...
 
template<typename Type , typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool openvdb::OPENVDB_VERSION_NAME::math::isNan (const Type &x)
 Return true if x is a NaN (Not-A-Number) value. 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::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::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 f)
 
int64_t openvdb::OPENVDB_VERSION_NAME::math::doubleToInt64 (const double d)
 
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 x2. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow3 (Type x)
 Return x3. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow4 (Type x)
 Return x4. More...
 
template<typename Type >
Type openvdb::OPENVDB_VERSION_NAME::math::Pow (Type x, int n)
 Return xn. 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 ex. 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 T >
auto openvdb::OPENVDB_VERSION_NAME::math::PrintCast (const T &val) -> typename std::enable_if<!std::is_same< T, int8_t >::value &&!std::is_same< T, uint8_t >::value, const T & >::type
 8-bit integer values print to std::ostreams as characters. Cast them so that they print as integers instead. More...
 
int32_t openvdb::OPENVDB_VERSION_NAME::math::PrintCast (int8_t val)
 
uint32_t openvdb::OPENVDB_VERSION_NAME::math::PrintCast (uint8_t val)
 
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::math::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::math::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::math::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::math::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...
 
template<typename T >
std::enable_if< std::is_same
< T, size_t >::value, T >
::type 
openvdb::OPENVDB_VERSION_NAME::math::Abs (T i)
 Return the absolute value of the given quantity. More...
 
float openvdb::OPENVDB_VERSION_NAME::math::Pow (float b, float e)
 Return be. More...
 
double openvdb::OPENVDB_VERSION_NAME::math::Pow (double b, double e)
 Return be. 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:1222
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222

Definition at line 421 of file Math.h.

#define OPENVDB_IS_POD (   Type)
Value:
#Type" must be a POD type (satisfy StandardLayoutType.)"); \
#Type" must be a POD type (satisfy TrivialType.)");
GLsizei const GLfloat * value
Definition: glcorearb.h:824

Definition at line 56 of file Math.h.

#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN

Definition at line 48 of file Math.h.

#define OPENVDB_NO_FP_EQUALITY_WARNING_END

Definition at line 49 of file Math.h.