Dry
Enumerations | Functions | Variables
MathDefs.h File Reference
#include "../Math/Random.h"
#include <cstdlib>
#include <cmath>
#include <limits>
#include <type_traits>

Enumerations

enum  Dry::Intersection { OUTSIDE, INTERSECTS, INSIDE }
 Intersection test result.
 

Functions

template<class T >
bool Dry::Equals (T lhs, T rhs)
 Check whether two floating point values are equal within accuracy.
 
template<class T , class U >
Dry::Lerp (T lhs, T rhs, U t)
 Linear interpolation between two values.
 
template<class T >
Dry::InverseLerp (T lhs, T rhs, T x)
 Inverse linear interpolation between two values.
 
template<class T , class U >
Dry::Min (T lhs, U rhs)
 Return the smaller of two values.
 
template<class T , class U >
Dry::Max (T lhs, U rhs)
 Return the larger of two values.
 
template<class T >
Dry::Abs (T value)
 Return absolute value of a value.
 
template<class T >
Dry::Sign (T value)
 Return the sign of a float (-1, 0 or 1.)
 
template<class T >
Dry::ToRadians (const T degrees)
 Convert degrees to radians.
 
template<class T >
Dry::ToDegrees (const T radians)
 Convert radians to degrees.
 
template<class T >
bool Dry::IsNaN (T value)
 Check whether a floating point value is NaN.
 
template<class T >
bool Dry::IsInf (T value)
 Check whether a floating point value is positive or negative infinity.
 
unsigned Dry::FloatToRawIntBits (float value)
 Return a representation of the specified floating-point value as a single format bit layout.
 
template<class T >
Dry::Clamp (T value, T min, T max)
 Clamp a number to a range.
 
template<class T >
Dry::SmoothStep (T lhs, T rhs, T t)
 Smoothly damp between values.
 
template<class T >
Dry::Sin (T angle)
 Return sine of an angle in degrees.
 
template<class T >
Dry::Cos (T angle)
 Return cosine of an angle in degrees.
 
template<class T >
Dry::Tan (T angle)
 Return tangent of an angle in degrees.
 
template<class T >
Dry::Asin (T x)
 Return arc sine in degrees.
 
template<class T >
Dry::Acos (T x)
 Return arc cosine in degrees.
 
template<class T >
Dry::Atan (T x)
 Return arc tangent in degrees.
 
template<class T >
Dry::Atan2 (T y, T x)
 Return arc tangent of y/x in degrees.
 
template<class T >
Dry::Pow (T x, T y)
 Return X in power Y.
 
template<class T >
Dry::PowN (T x, int y)
 Return X to the power of int Y.
 
template<class T >
Dry::Ln (T x)
 Return natural logarithm of X.
 
template<class T >
Dry::Sqrt (T x)
 Return square root of X.
 
template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
Dry::Mod (T x, T y)
 Return remainder of X/Y for float values. More...
 
template<class T >
Dry::AbsMod (T x, T y)
 Return always positive remainder of X/Y.
 
template<class T >
Dry::Fract (T value)
 Return fractional part of passed value in range [0, 1).
 
template<class T >
Dry::Floor (T x)
 Round value down.
 
template<class T >
int Dry::FloorToInt (T x)
 Round value down. Returns integer value.
 
template<class T >
Dry::Round (T x)
 Round value to nearest integer.
 
template<class Iterator >
auto Dry::Sum (Iterator begin, Iterator end) -> typename std::decay< decltype(*begin)>::type
 Compute total value of the range.
 
template<class Iterator >
auto Dry::Average (Iterator begin, Iterator end) -> typename std::decay< decltype(*begin)>::type
 Compute average value of the range.
 
template<class T >
int Dry::RoundToInt (T x)
 Round value to nearest integer.
 
template<class T >
Dry::RoundToNearestMultiple (T x, T multiple)
 Round value to nearest multiple.
 
template<class T >
Dry::Ceil (T x)
 Round value up.
 
template<class T >
int Dry::CeilToInt (T x)
 Round value up.
 
bool Dry::IsPowerOfTwo (unsigned value)
 Check whether an unsigned integer is a power of two.
 
unsigned Dry::NextPowerOfTwo (unsigned value)
 Round up to next power of two.
 
unsigned Dry::ClosestPowerOfTwo (unsigned value)
 Round up or down to the closest power of two.
 
unsigned Dry::LogBaseTwo (unsigned value)
 Return log base two or the MSB position of the given value.
 
unsigned Dry::CountSetBits (unsigned value)
 Count the number of set bits in a mask.
 
constexpr unsigned Dry::SDBMHash (unsigned hash, unsigned char c)
 Update a hash with the given 8-bit value using the SDBM algorithm.
 
float Dry::Random ()
 Return a random float between 0.0 (inclusive) and 1.0 (exclusive.)
 
float Dry::Random (float range)
 Return a random float between 0.0 and range, inclusive from both ends.
 
float Dry::Random (float min, float max)
 Return a random float between min and max, inclusive from both ends.
 
int Dry::Random (int range)
 Return a random integer between 0 and range - 1.
 
int Dry::Random (int min, int max)
 Return a random integer between min and max - 1.
 
int Dry::DiceRoll (int dice, int sides=6)
 Return the result of a dice roll.
 
float Dry::RandomNormal (float meanValue, float variance)
 Return a random normal distributed number with the given mean value and variance.
 
unsigned short Dry::FloatToHalf (float value)
 Convert float to half float. From https://gist.github.com/martinkallman/5049614.
 
float Dry::HalfToFloat (unsigned short value)
 Convert half float to float. From https://gist.github.com/martinkallman/5049614.
 
void Dry::SinCos (float angle, float &sin, float &cos)
 Calculate both sine and cosine, with angle in degrees.
 

Variables

static const float Dry::M_TAU { 6.283185307179586476925f }
 
static const float Dry::M_PI { M_TAU * 0.5f }
 
static const float Dry::M_PI_2 { M_PI * 0.5f }
 
static const float Dry::M_PHI { 1.618033988749894848205f }
 
static const float Dry::M_SQRT3 { 1.732050807568877293527f }
 
static const float Dry::M_1_SQRT2 { 0.70710678118654752440f }
 
static const float Dry::M_1_SQRT3 { 0.577350269189625764509f }
 
static const int Dry::M_MIN_INT { static_cast<int>(0x80000000) }
 
static const int Dry::M_MAX_INT { static_cast<int>(0x7fffffff) }
 
static const unsigned Dry::M_MIN_UNSIGNED { 0x00000000 }
 
static const unsigned Dry::M_MAX_UNSIGNED { 0xffffffff }
 
static const float Dry::M_MAX_FLOAT { std::numeric_limits<float>::max() }
 
static const float Dry::M_EPSILON { 0.000001f }
 
static const float Dry::M_LARGE_EPSILON { 0.00005f }
 
static const float Dry::M_MIN_NEARCLIP { 0.01f }
 
static const float Dry::M_MAX_FOV { 160.0f }
 
static const float Dry::M_LARGE_VALUE { 100000000.0f }
 
static const float Dry::M_INFINITY { static_cast<float>(HUGE_VAL) }
 
static const float Dry::M_DEGTORAD { M_PI / 180.0f }
 
static const float Dry::M_DEGTORAD_2 { M_PI / 360.0f }
 
static const float Dry::M_RADTODEG { 1.0f / M_DEGTORAD }
 

Function Documentation

◆ Mod()

template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
T Dry::Mod ( x,
y 
)
inline

Return remainder of X/Y for float values.

Return remainder of X/Y for integer values.