Skip to content

Commit

Permalink
libcore: Sign function uses enumerations
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent a1f593e commit 8722094
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doomsday/libs/core/include/de/math.h
Expand Up @@ -181,6 +181,28 @@ inline bool fequal(ddouble a, ddouble b, ddouble precision) {
return abs(a - b) < abs(precision);
}

enum class Sign { Positive, Zero, Negative };

template <typename Type>
inline Sign sign(Type const &a) {
if (a < Type(0)) return Sign::Negative;
if (a > Type(0)) return Sign::Positive;
return Sign::Zero;
inline Type asNumber(Sign s) {
}

template <typename Type>
if (s == Sign::Negative) return -1;
if (s == Sign::Positive) return +1;
return 0;
}

template <typename Type>
inline Type operator *(Sign s, Type t) { return asNumber<Type>(s) * t; }

template <typename Type>
inline Type operator *(Type t, Sign s) { return t * asNumber<Type>(s); }

template <typename Type>
inline Type degreeToRadian(Type degree) {
return degree * PI / Type(180);
Expand Down

0 comments on commit 8722094

Please sign in to comment.