Nebula
Loading...
Searching...
No Matches
scalar.h File Reference

Detailed Description

Nebula's scalar datatype.

NOTE: do not add CRT math function calls to this call, but instead into the platform specific headers functions are called and must be placed into a .cc file, not into the header.

Go to the source code of this file.

Classes

struct  Math::float2
 
struct  Math::float3
 
struct  Math::float4
 
struct  Math::int2
 
struct  Math::int3
 
struct  Math::int4
 
struct  Math::uint2
 
struct  Math::uint3
 
struct  Math::uint4
 
struct  Math::byte4u
 
struct  Math::byte4
 
struct  Math::randxorstate
 fast random generator based on xorshift+ More...
 

Namespaces

namespace  Math
 Different curves.
 

Macros

#define PI   (3.1415926535897932384626433832795028841971693993751)
 
#define N_PI   (Math::scalar(PI))
 
#define N_PI_DOUBLE   (Math::scalar(6.283185307179586476925286766559))
 
#define N_PI_HALF   (Math::scalar(1.5707963267948966192313216916398f))
 
#define TINY   (0.0000001f)
 
#define N_TINY   TINY
 

Typedefs

typedef float Math::scalar
 
typedef float Math::float32
 
typedef double Math::float64
 

Functions

__forceinline scalar Math::rand ()
 Return a pseudo random number between 0 and 1.
 
__forceinline scalar Math::rand (scalar min, scalar max)
 Return a pseudo random number between min and max.
 
__forceinline scalar Math::sin (scalar x)
 
__forceinline scalar Math::cos (scalar x)
 
__forceinline scalar Math::tan (scalar x)
 
__forceinline scalar Math::asin (scalar x)
 
__forceinline scalar Math::acos (scalar x)
 
__forceinline scalar Math::atan (scalar x)
 
__forceinline scalar Math::sqrt (scalar x)
 
__forceinline int Math::fchop (scalar f)
 Chop float to int.
 
__forceinline scalar Math::fmod (scalar x, scalar y)
 
__forceinline scalar Math::modangle (scalar a)
 Normalize an angular value into the range rad(0) to rad(360).
 
__forceinline scalar Math::log2 (scalar f)
 log2() function.
 
__forceinline scalar Math::exp2 (scalar x)
 
__forceinline scalar Math::log (scalar x)
 get logarithm of x
 
__forceinline scalar Math::exp (scalar x)
 
__forceinline int Math::frnd (scalar f)
 Round float to integer.
 
__forceinline scalar Math::pow (scalar x, scalar y)
 
__forceinline bool Math::fequal (scalar f0, scalar f1, scalar tol)
 A fuzzy floating point equality check.
 
template<typename TYPE >
__forceinline TYPE Math::max (TYPE a, TYPE b)
 
template<typename TYPE0 , typename ... TYPEN>
__forceinline TYPE0 Math::max (TYPE0 first, TYPE0 second, TYPEN... rest)
 
template<>
__forceinline unsigned int Math::max (unsigned int a, unsigned int b)
 branchless max for uint32
 
template<typename TYPE >
__forceinline TYPE Math::min (TYPE a, TYPE b)
 
template<>
__forceinline unsigned int Math::min (unsigned int a, unsigned int b)
 branchless min for uints
 
template<>
__forceinline uint16_t Math::min (uint16_t a, uint16_t b)
 branchless min for uints
 
template<typename TYPE0 , typename ... TYPEN>
__forceinline TYPE0 Math::min (TYPE0 first, TYPE0 second, TYPEN... rest)
 
__forceinline scalar Math::abs (scalar a)
 
__forceinline double Math::abs (double a)
 
__forceinline int Math::abs (int a)
 
__forceinline scalar Math::sgn (scalar a)
 
__forceinline constexpr scalar Math::deg2rad (scalar d)
 
__forceinline constexpr scalar Math::rad2deg (scalar r)
 
__forceinline float Math::clamp (float val, float minVal, float maxVal)
 Float clamping.
 
__forceinline int64_t Math::clamp (int64_t val, int64_t minVal, int64_t maxVal)
 int clamping.
 
__forceinline int32_t Math::clamp (int32_t val, int32_t minVal, int32_t maxVal)
 int clamping.
 
__forceinline float Math::ceil (float val)
 Floating point ceiling.
 
__forceinline float Math::floor (float val)
 Floating point flooring.
 
__forceinline float Math::round (float val)
 Floating point rounding.
 
__forceinline bool Math::fless (scalar f0, scalar f1, scalar tol)
 A fuzzy floating point less-then check.
 
__forceinline bool Math::fgreater (scalar f0, scalar f1, scalar tol)
 A fuzzy floating point greater-then check.
 
__forceinline scalar Math::saturate (scalar val)
 Saturate a value (clamps between 0.0f and 1.0f)
 
__forceinline double Math::saturate (double val)
 Saturate a value (clamps between 0.0f and 1.0f)
 
__forceinline float Math::lerp (float x, float y, float l)
 Linearly interpolate between 2 values: ret = x + l * (y - x)
 
__forceinline scalar Math::angulardistance (scalar from, scalar to)
 Get angular distance.
 
__forceinline bool Math::isdenormal (scalar s)
 Returns true if the input scalar is denormalized (#DEN)
 
__forceinline float Math::undenormalize (scalar s)
 Returns 0 if scalar is denormal.
 
__forceinline bool Math::nearequal (scalar a, scalar b, scalar epsilon)
 test of nearly equal given a tolerance (epsilon)
 
__forceinline scalar Math::cot (scalar x)
 
__forceinline scalar Math::smoothstep (scalar edge0, scalar edge1, scalar x)
 
__forceinline int Math::irand (int min, int max)
 Return a pseudo integer random number between min and max.
 
__forceinline int Math::mostsignificant (unsigned int val)
 Returns the position of the most significant bit of the number.
 
__forceinline unsigned int Math::align (unsigned int alignant, unsigned int alignment)
 
__forceinline uintptr_t Math::alignptr (uintptr_t alignant, uintptr_t alignment)
 
__forceinline unsigned int Math::align_down (unsigned int alignant, unsigned int alignment)
 
__forceinline uintptr_t Math::align_downptr (uintptr_t alignant, uintptr_t alignment)
 
__forceinline unsigned int Math::divandroundup (unsigned int dividend, unsigned int divider)
 Integer division with rounding.
 
__forceinline unsigned int Math::roundtopow2 (unsigned int val)
 Rounds up to next power of 2.
 
__forceinline uint64 Math::randxor (randxorstate &state)
 
__forceinline uint32_t Math::pointerhash (void *ptr)
 cheap pointer hash using modulo with a mersenne prime
 
long double operator""_rad (long double deg)
 Convert degrees to radians.
 
long double operator""_rad (unsigned long long deg)
 
long double operator""_deg (long double rad)
 Convert radians to degrees.
 
long double operator""_deg (unsigned long long deg)
 

Macro Definition Documentation

◆ N_PI

#define N_PI   (Math::scalar(PI))

◆ N_PI_DOUBLE

#define N_PI_DOUBLE   (Math::scalar(6.283185307179586476925286766559))

◆ N_PI_HALF

#define N_PI_HALF   (Math::scalar(1.5707963267948966192313216916398f))

◆ N_TINY

#define N_TINY   TINY

◆ PI

#define PI   (3.1415926535897932384626433832795028841971693993751)

◆ TINY

#define TINY   (0.0000001f)

Function Documentation

◆ operator""_deg() [1/2]

long double operator""_deg ( long double rad)
inline

Convert radians to degrees.

◆ operator""_deg() [2/2]

long double operator""_deg ( unsigned long long deg)
inline

◆ operator""_rad() [1/2]

long double operator""_rad ( long double deg)
inline

Convert degrees to radians.

◆ operator""_rad() [2/2]

long double operator""_rad ( unsigned long long deg)
inline