71 return std::max(min, std::min(val, max));
78 return (dividend + divisor-1) / divisor;
95 inline bool feq(
double d1,
double d2,
double epsilon = 0.00001)
97 return fabs(d1 - d2) < epsilon;
100 inline bool feqf(
float f1,
float f2,
float epsilon = 0.001f)
102 return fabsf(f1 - f2) < epsilon;
107 const double relativeError = fabs(d1/d2 - 1.0);
108 if(relativeError > relativeErrorTolerance)
140 const u8 max = std::numeric_limits<u8>::max();
142 throw std::out_of_range(
"u8_from_larger");
143 return (
u8)(x & max);
148 const u16 max = std::numeric_limits<u16>::max();
150 throw std::out_of_range(
"u16_from_larger");
151 return (
u16)(x & max);
156 const u32 max = std::numeric_limits<u32>::max();
158 throw std::out_of_range(
"u32_from_larger");
159 return (
u32)(x & max);
167 #endif // #ifndef INCLUDED_LIB
u8 u8_from_double(double in)
convert double to u8; verifies number is in range.
T DivideRoundUp(T dividend, T divisor)
u8 u8_from_larger(T x)
assemble u32 from u16
u16 u32_lo(u32 x)
return upper 16-bits
u16 u16_from_double(double in)
convert double to u16; verifies number is in range.
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
T Clamp(T val, T min, T max)
low-level aka "lib"
u32 u64_lo(u64 x)
return upper 32-bits
u32 u32_from_u16(u16 hi, u16 lo)
assemble u64 from u32
u16 u32_hi(u32 x)
return lower 32-bits
bool IsSimilarMagnitude(double d1, double d2, const double relativeErrorTolerance=0.05)
#define T(string_literal)
u64 u64_from_u32(u32 hi, u32 lo)
return lower 16-bits
bool feq(double d1, double d2, double epsilon=0.00001)
are the given floats nearly "equal"?
bool feqf(float f1, float f2, float epsilon=0.001f)