Skip to content

Commit

Permalink
sgn function improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Jan 8, 2025
1 parent 9c5a8a5 commit fabd197
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/units/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ template <isQuantity Q, isQuantity R> constexpr Q min(const Q& lhs, const R& rhs
return (lhs < rhs ? lhs : rhs);
}

template <isQuantity Q> constexpr Number sgn(const Q& lhs) {
if (lhs.internal() > 0) return 1;
if (lhs.internal() < 0) return -1;
return 0;
constexpr double sgn(double lhs) {
if (lhs > 0) return 1;
if (lhs < 0) return -1;
return lhs;
}

template <isQuantity Q> constexpr double sgn(Q lhs) { return sgn(lhs.internal()); }

template <int R, isQuantity Q, isQuantity S = Exponentiated<Q, std::ratio<R>>> constexpr S pow(const Q& lhs) {
return S(std::pow(lhs.internal(), R));
}
Expand Down

0 comments on commit fabd197

Please sign in to comment.