Skip to content

Commit

Permalink
Removed LANGULUS_ERROR macro entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Oct 18, 2024
1 parent 1a9fcd1 commit 1238d23
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 93 deletions.
46 changes: 24 additions & 22 deletions source/Functions/Arithmetics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace Langulus::Math
else if constexpr (CT::Signed<T>)
return a < T {0} ? -a : a;
else
LANGULUS_ERROR("T must either have Abs() method, or be a number");
static_assert(false, "T must either have Abs() method, or be a number");
}

/// Signed unit
Expand All @@ -179,7 +179,7 @@ namespace Langulus::Math
else if constexpr (CT::Signed<T>)
return a < T {0} ? T {-1} : T {1};
else
LANGULUS_ERROR("T must either have Sign() method, or be a number");
static_assert(false, "T must either have Sign() method, or be a number");
}

/// Calculate base to the power of the exponent
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace Langulus::Math
else if constexpr (CT::Real<B, E>)
return ::std::pow(FundamentalCast(base), FundamentalCast(exponent));
else
LANGULUS_ERROR("T must either have Pow(exponent) method, or be a number");
static_assert(false, "T must either have Pow(exponent) method, or be a number");
}

/// Get the smallest of the provided
Expand All @@ -224,7 +224,7 @@ namespace Langulus::Math
else if constexpr (CT::Sortable<T1, T2>)
return t1 < t2 ? Forward<T1>(t1) : Forward<T2>(t2);
else
LANGULUS_ERROR("T must either have Min(t2) method, or be sortable");
static_assert(false, "T must either have Min(t2) method, or be sortable");
}
else return Min(Min(Forward<T1>(t1), Forward<T2>(t2)), Forward<TAIL>(tail)...);
}
Expand All @@ -239,7 +239,7 @@ namespace Langulus::Math
else if constexpr (CT::Sortable<T1, T2>)
return t1 > t2 ? Forward<T1>(t1) : Forward<T2>(t2);
else
LANGULUS_ERROR("T must either have Max(t2) method, or be sortable");
static_assert(false, "T must either have Max(t2) method, or be sortable");
}
else return Max(Max(Forward<T1>(t1), Forward<T2>(t2)), Forward<TAIL>(tail)...);
}
Expand All @@ -255,7 +255,7 @@ namespace Langulus::Math
else if constexpr (CT::Real<T>)
return ::std::round(a);
else
LANGULUS_ERROR("T must either have Round() method, or be a number");
static_assert(false, "T must either have Round() method, or be a number");
}

/// Round and return an integer
Expand All @@ -274,7 +274,7 @@ namespace Langulus::Math
const auto aa = static_cast<Double>(a) + Double {6755399441055744.0};
return int {reinterpret_cast<const int&>(aa)};
}
else LANGULUS_ERROR("T must either have Round() method, or be a number");
else static_assert(false, "T must either have Round() method, or be a number");
}*/

/// Floor
Expand All @@ -289,7 +289,7 @@ namespace Langulus::Math
const auto round_a = Round<T>(a);
return round_a <= a ? round_a : round_a - T {1};
}
else LANGULUS_ERROR("T must either have Floor() method, or be a number");
else static_assert(false, "T must either have Floor() method, or be a number");
}

/// Floor and return an integer
Expand All @@ -311,7 +311,7 @@ namespace Langulus::Math
const auto round_a = Round<T>(a);
return round_a >= a ? round_a : round_a + T(1);
}
else LANGULUS_ERROR("T must either have Ceil() method, or be a number");
else static_assert(false, "T must either have Ceil() method, or be a number");
}

/// Ceil and return an integer
Expand All @@ -328,7 +328,7 @@ namespace Langulus::Math
if constexpr (CT::Multipliable<T, T>)
return n * n;
else
LANGULUS_ERROR("T must be CT::Multipliable");
static_assert(false, "T must be CT::Multipliable");
}

namespace Detail
Expand Down Expand Up @@ -379,7 +379,7 @@ namespace Langulus::Math
} while (r < p);
return p;
}
else LANGULUS_ERROR("T must either have Sqrt() method, or be a number");
else static_assert(false, "T must either have Sqrt() method, or be a number");
}

/// Get a fractional part
Expand All @@ -393,7 +393,7 @@ namespace Langulus::Math
else if constexpr (CT::Integer<T>)
return T {0};
else
LANGULUS_ERROR("T must either have Frac() method, or be a number");
static_assert(false, "T must either have Frac() method, or be a number");
}

/// Modulate
Expand All @@ -405,7 +405,7 @@ namespace Langulus::Math
else if constexpr (CT::Number<T1, T2>)
return x - y * Floor(x / y);
else
LANGULUS_ERROR("T must either have Mod(y) method, or be a number");
static_assert(false, "T must either have Mod(y) method, or be a number");
}

/// Remaps a [0; 1] range to a [-1; 1] range
Expand All @@ -424,7 +424,7 @@ namespace Langulus::Math
else if constexpr (CT::Number<T, MIN, MAX>)
return v < min ? min : (v > max ? max : v);
else
LANGULUS_ERROR("T must either have Clamp(min, max) method, or be a number");
static_assert(false, "T must either have Clamp(min, max) method, or be a number");
}

/// Clamp a value inside the interval [0:1]
Expand All @@ -447,7 +447,7 @@ namespace Langulus::Math
return v - min > halfd ? max : min;
return v;
}
else LANGULUS_ERROR("T must either have ClampRev(min, max) method, or be a number");
else static_assert(false, "T must either have ClampRev(min, max) method, or be a number");
}

/// Dot product
Expand All @@ -456,7 +456,8 @@ namespace Langulus::Math
constexpr auto Dot(const T1& a, const T2& b) noexcept {
if constexpr (CT::HasDot<T1, T2>)
return a.Dot(b);
else LANGULUS_ERROR("T must have Dot(b) method");
else
static_assert(false, "T must have Dot(b) method");
}

/// Self dot product
Expand All @@ -472,7 +473,8 @@ namespace Langulus::Math
constexpr auto Cross(const T1& a, const T2& b) noexcept {
if constexpr (CT::HasCross<T1, T2>)
return a.Cross(b);
else LANGULUS_ERROR("T must have Cross(b) method");
else
static_assert(false, "T must have Cross(b) method");
}

/// Get length (as in magnitude)
Expand All @@ -486,7 +488,7 @@ namespace Langulus::Math
else if constexpr (CT::Character<T>)
return Abs(v);
else
LANGULUS_ERROR("T must either have Length() method, or be a number");
static_assert(false, "T must either have Length() method, or be a number");
}

/// Distance
Expand All @@ -503,7 +505,7 @@ namespace Langulus::Math
if constexpr (CT::HasNormalize<T>)
return v.Normalize();
else
LANGULUS_ERROR("T must have Normalize() method");
static_assert(false, "T must have Normalize() method");
}

/// Step function
Expand All @@ -515,7 +517,7 @@ namespace Langulus::Math
else if constexpr (CT::Number<T, EDGE>)
return x < edge ? T {0} : T {1};
else
LANGULUS_ERROR("T must either have Step(edge) method, or be a number");
static_assert(false, "T must either have Step(edge) method, or be a number");
}

/// Smooth step (Hermite) interpolation, analogous to the GLSL function
Expand All @@ -537,7 +539,7 @@ namespace Langulus::Math
else if constexpr (CT::Number<T>)
return ::std::exp(x);
else
LANGULUS_ERROR("T must either have Exp() method, or be a number");
static_assert(false, "T must either have Exp() method, or be a number");
}

/// Solve 2^x
Expand All @@ -557,7 +559,7 @@ namespace Langulus::Math
LANGULUS_ASSUME(UserAssumes, n >= 0, "Can't get sum of non-positive integers");
return (n * (n + T {1})) / T {2};
}
else LANGULUS_ERROR("T must either have Sum() method, or be a number");
else static_assert(false, "T must either have Sum() method, or be a number");
}

/// A Kahan summation used to minimize floating-point math error
Expand Down
10 changes: 5 additions & 5 deletions source/Matrices/TMatrix.inl
Original file line number Diff line number Diff line change
Expand Up @@ -480,31 +480,31 @@ namespace Langulus::Math
constexpr auto TME()::GetRight() const noexcept -> TVector<T, 3> {
if constexpr (IsSquare and Rows > 2)
return {mColumns[0][0], mColumns[1][0], mColumns[2][0]};
else LANGULUS_ERROR("Can't get right axis of this matrix");
else static_assert(false, "Can't get right axis of this matrix");
}

/// Get up axis
TEMPLATE() LANGULUS(INLINED)
constexpr auto TME()::GetUp() const noexcept -> TVector<T, 3> {
if constexpr (IsSquare and Rows > 2)
return {mColumns[0][1], mColumns[1][1], mColumns[2][1]};
else LANGULUS_ERROR("Can't get up axis of this matrix");
else static_assert(false, "Can't get up axis of this matrix");
}

/// Get view axis
TEMPLATE() LANGULUS(INLINED)
constexpr auto TME()::GetView() const noexcept -> TVector<T, 3> {
if constexpr (IsSquare and Rows > 2)
return {mColumns[0][2], mColumns[1][2], mColumns[2][2]};
else LANGULUS_ERROR("Can't get view axis of this matrix");
else static_assert(false, "Can't get view axis of this matrix");
}

/// Get translation
TEMPLATE() LANGULUS(INLINED)
constexpr auto TME()::GetScale() const noexcept -> TVector<T, 3> {
if constexpr (IsSquare and Rows > 2)
return {GetRight().Length(), GetUp().Length(), GetView().Length()};
else LANGULUS_ERROR("Can't get translation of this matrix");
else static_assert(false, "Can't get translation of this matrix");
}

/// Get translation
Expand Down Expand Up @@ -797,7 +797,7 @@ namespace Langulus::Math
(n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33)* detInv,
};
}
else LANGULUS_ERROR("Matrix inversion code not implemented");
else static_assert(false, "Matrix inversion code not implemented");
}


Expand Down
2 changes: 1 addition & 1 deletion source/Numbers/TAngle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ namespace Langulus
for (auto i : "Roll")
name[offset++] = i;
}
else LANGULUS_ERROR("Unsupported dimension");
else static_assert(false, "Unsupported dimension");

// Write angle suffix if degrees
// Radians have no suffix by default
Expand Down
14 changes: 8 additions & 6 deletions source/Numbers/TNumber.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace Langulus::Math
mValue = a.mValue;
else if constexpr (CT::Convertible<ALT, T>)
mValue = static_cast<T>(a);
else LANGULUS_ERROR("Bad number construction");
else
static_assert(false, "Bad number construction");
}

/// Assign any number-convertible thing
Expand All @@ -42,7 +43,8 @@ namespace Langulus::Math
mValue = a.mValue;
else if constexpr (CT::Convertible<ALT, T>)
mValue = static_cast<T>(a);
else LANGULUS_ERROR("Bad number assignment");
else
static_assert(false, "Bad number assignment");
return *this;
}

Expand Down Expand Up @@ -243,7 +245,7 @@ namespace Langulus::Math
* ::std::floor(FundamentalCast(lhs) / FundamentalCast(rhs))};
}
}
else LANGULUS_ERROR("Incompatible custom numbers for modulation");
else static_assert(false, "Incompatible custom numbers for modulation");
}

template<CT::NumberBased LHS, CT::BuiltinNumber N> LANGULUS(INLINED)
Expand Down Expand Up @@ -271,7 +273,7 @@ namespace Langulus::Math
else if constexpr (CT::DerivedFrom<RHS, LHS>)
return RHS {FundamentalCast(lhs) << FundamentalCast(rhs)};
else
LANGULUS_ERROR("Incompatible custom numbers for left bitshift");
static_assert(false, "Incompatible custom numbers for left bitshift");
}

template<CT::NumberBased LHS, CT::BuiltinNumber N>
Expand All @@ -295,7 +297,7 @@ namespace Langulus::Math
else if constexpr (CT::DerivedFrom<RHS, LHS>)
return RHS {FundamentalCast(lhs) >> FundamentalCast(rhs)};
else
LANGULUS_ERROR("Incompatible custom numbers for right bitshift");
static_assert(false, "Incompatible custom numbers for right bitshift");
}

template<CT::NumberBased LHS, CT::BuiltinNumber N>
Expand All @@ -319,7 +321,7 @@ namespace Langulus::Math
else if constexpr (CT::DerivedFrom<RHS, LHS>)
return RHS {FundamentalCast(lhs) ^ FundamentalCast(rhs)};
else
LANGULUS_ERROR("Incompatible custom numbers for xor");
static_assert(false, "Incompatible custom numbers for xor");
}

template<CT::NumberBased LHS, CT::BuiltinNumber N>
Expand Down
2 changes: 1 addition & 1 deletion source/Primitives/TTorus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Langulus::Math
const auto q = TVector<TypeOf<T>, 2>(point.xy().Length() - mOuterRadius, point[2]);
return q.Length() - mInnerRadius;
}
else LANGULUS_ERROR("Unsupported dimension");
else static_assert(false, "Unsupported dimension");
}
};

Expand Down
2 changes: 1 addition & 1 deletion source/Quaternions/TQuaternion.inl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace Langulus::Math
else if constexpr (CT::Same<D, Traits::Z>)
return FromAxis(TVector<T, 4>{0, 0, 1, 0}, angle);
else
LANGULUS_ERROR("Unsupported dimension");
static_assert(false, "Unsupported dimension");
}

/// Constructor from axii and angles
Expand Down
10 changes: 5 additions & 5 deletions source/Randomness/Hashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace Langulus::Math
return Frac((p4.xxyz() + p4.yzzw()) * p4.zywx());
}
}
else LANGULUS_ERROR("Hash function with this output doesn't exist, for input 1");
else static_assert(false, "Hash function with this output doesn't exist, for input 1");
}
else if constexpr (DIN == 2) {
if constexpr (DOUT == 1) {
Expand Down Expand Up @@ -213,7 +213,7 @@ namespace Langulus::Math
return Frac((p4.xxyz() + p4.yzzw()) * p4.zywx());
}
}
else LANGULUS_ERROR("Hash function with this output doesn't exist, for input 2");
else static_assert(false, "Hash function with this output doesn't exist, for input 2");
}
else if constexpr (DIN == 3) {
if constexpr (DOUT == 1) {
Expand Down Expand Up @@ -298,7 +298,7 @@ namespace Langulus::Math
return Frac((p4.xxyz() + p4.yzzw()) * p4.zywx());
}
}
else LANGULUS_ERROR("Hash function with this output doesn't exist, for input 3");
else static_assert(false, "Hash function with this output doesn't exist, for input 3");
}
else if constexpr (DIN == 4) {
if constexpr (DOUT == 1) {
Expand Down Expand Up @@ -383,9 +383,9 @@ namespace Langulus::Math
return Frac((p.xxyz() + p.yzzw()) * p.zywx());
}
}
else LANGULUS_ERROR("Hash function with this output doesn't exist, for input 4");
else static_assert(false, "Hash function with this output doesn't exist, for input 4");
}
else LANGULUS_ERROR("Hash function with this input doesn't exist");
else static_assert(false, "Hash function with this input doesn't exist");
}
};

Expand Down
4 changes: 2 additions & 2 deletions source/Randomness/MersenneTwister.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Langulus::Math
::std::uniform_real_distribution<T> dist(-1, 1);
return dist(mStdGenerator);
}
else LANGULUS_ERROR("Unsupported number type");
else static_assert(false, "Unsupported number type");
}

/// Provide random numbers for different number types, in a range
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace Langulus::Math
::std::uniform_real_distribution<T> dist(min, max);
result = dist(mStdGenerator);
}
else LANGULUS_ERROR("Unsupported number type");
else static_assert(false, "Unsupported number type");

if constexpr (!MIN_INCLUSIVE) {
// Offset from lower limit
Expand Down
Loading

0 comments on commit 1238d23

Please sign in to comment.