17 typedef typename std::make_unsigned<Int>::type UInt;
21 static Int
abs(Int x) {
return x >= 0 ? x : -x; }
23 static UInt
abs(UInt x) {
return x; }
28 static Int
sign(Int x) {
return x > 0 ? 1 : x < 0 ? -1 : 0; }
29 static UInt
sign(UInt x) {
return x > 0 ? 1 : 0; }
50 return norm > mod ? -mod*2 + norm : norm < -mod ? mod*2 + norm : norm;
56 return abs(dist) > mod ? (dist >= 0 ? dist - mod*2 : dist + mod*2) : dist;
60 template<
class Num>
static Num
sqr(Num x) {
return x*x; }
87 template<
class Num,
class Num2>
88 static typename std::common_type<Num, Num2>::type
89 min(Num a, Num2 b) {
return a <= b ? a : b; }
92 template<
class Num,
class Num2>
93 static typename std::common_type<Num, Num2>::type
94 max(Num a, Num2 b) {
return a >= b ? a : b; }
97 template<
class Num,
class Num2,
class Num3>
98 static typename std::common_type<Num, Num2, Num3>::type
99 clamp(Num val, Num2
min, Num3
max) {
return val < min ? min : val > max ? max : val; }
105 static bool isNear(Int a, Int b, Int tol) {
return abs(a - b) <= tol; }
111 template<
class Num,
class Num2,
class Num3>
static Real pow(Real x, Real y)
x raised to exponent y
Definition: Alge.h:73
Algebra.
Definition: Alge.h:13
static Real frac(Real x)
Remove the whole part, leaving just the fraction.
Definition: Alge.h:42
static Int sign(Int x)
Get sign of number {-1,0,1}.
Definition: Alge.h:28
Inherit to declare that class is not copyable.
Definition: Meta.h:286
static Real trunc(Real x)
Remove fractional part, leaving just the whole number.
Definition: Alge.h:40
static Real round(Real x)
Round to the nearest whole number.
Definition: Alge.h:37
static Real exp(Real x)
Euler's number e raised to exponent x (e^x)
Definition: Alge.h:68
static Real sqrtInv(Real x)
Inverse Square Root.
Definition: Alge.h:65
Alge_< Real > Alge
Definition: Alge.h:130
static Real sqrt(Real x)
Square Root.
Definition: Alge.h:63
Alge_< Float > Alge_f
Definition: Alge.h:131
static Real floor(Real x)
Round down to the nearest whole number towards -inf.
Definition: Alge.h:35
static Real expm1(Real x)
exp(x) - 1, more accurate than exp() for small values of x.
Definition: Alge.cpp:57
static bool isNan(Real x)
Returns true if real is not a number.
Definition: Alge.h:102
static Real ceil(Real x)
Round up to the nearest whole number towards +inf.
Definition: Alge.h:33
static std::common_type< Num, Num2 >::type max(Num a, Num2 b)
Get the maximum of two numbers.
Definition: Alge.h:94
Alge_< Double > Alge_d
Definition: Alge.h:132
static Real abs(Real x)
Get absolute value of real number.
Definition: Alge.h:25
static const Real logMin
The lowest negative value x for which exp(x) can be calucated without underflow.
Definition: Alge.h:76
Alge_< Quad > Alge_q
Definition: Alge.h:133
static Int abs(Int x)
Get absolute value of signed integer.
Definition: Alge.h:21
static std::common_type< Num, Num2 >::type min(Num a, Num2 b)
Get the minimum of two numbers.
Definition: Alge.h:89
static bool isNear(Int a, Int b, Int tol)
Check whether two numbers are near each other, given a tolerance.
Definition: Alge.h:105
static std::common_type< Num, Num2, Num3 >::type clamp(Num val, Num2 min, Num3 max)
Ensure that a number is within a range.
Definition: Alge.h:99
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
static bool isNearZero(Real val, Real tol=Real_::zeroTol)
Check whether a number is close to zero.
Definition: Alge.h:108
static bool isNear(Real a, Real b, Real tol=Real_::zeroTol)
Definition: Alge.h:106
static Real log1p(Real x)
log(1 + x), more accurate than log() for small values of x.
Definition: Alge.cpp:13
static Real modDistSigned(Real mod, Real x, Real y)
Calc smallest signed distance between two normalized values in a modular field.
Definition: Alge.h:53
static Num sqr(Num x)
Square.
Definition: Alge.h:60
static UInt sign(UInt x)
Definition: Alge.h:29
static const Real logMax
The highest value x for which exp(x) can be calucated without overflow.
Definition: Alge.h:78
static bool isInRange(Num val, Num2 min, Num3 max)
Check if value is within min/max inclusive range.
Definition: Alge.h:112
static tuple< bool, Real, Real > solve(Real a, Real b, Real c, Real d, Real u, Real v)
Solve an equation pair using Gauss-Jordan elimination.
Definition: Alge.cpp:102
static Real modNormalize(Real mod, Real val)
Get an equivalent value in the normalized modular interval [-mod, mod].
Definition: Alge.h:47
static Real hypot(Real a, Real b)
Get the hypotenuse of a right angle triangle with side lengths a and b. This method is more numerical...
Definition: Alge.cpp:84
static Real sign(Real x)
Definition: Alge.h:30
static UInt abs(UInt x)
Get absolute value of unsigned integer.
Definition: Alge.h:23
Global Honeycomb namespace.
static Real mod(Real x, Real y)
Modulo, same as x % y. Returns remainder of division: x/y.
Definition: Alge.h:45
static Real log(Real x, Real base)
Logarithm with base number.
Definition: Alge.h:82
static Real log(Real x)
Natural logarithm. ie. ln(x)
Definition: Alge.h:80