Skip to content

Commit

Permalink
revert units.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Jan 7, 2025
1 parent 2e7ff00 commit ad56124
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions include/units/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,22 @@ NEW_UNIT(Luminosity, candela, 0, 0, 0, 0, 0, 0, 1, 0);
NEW_UNIT(Moles, mol, 0, 0, 0, 0, 0, 0, 0, 1);

namespace units {
// helper function for Quantity-Double compatibility
template <isQuantity Q> constexpr double getInternal(const Q& lhs) { return lhs.internal(); }

constexpr double getInternal(double lhs) { return lhs; }
constexpr bool isNan(double lhs) {
// Use the fact that NaN is not equal to itself
return lhs != lhs;
}

template <isArithmetic Q> constexpr bool isNan(const Q& lhs) { return lhs != lhs; }
template <isQuantity Q> constexpr bool isNan(const Q& lhs) { return isNan(lhs.internal()); }

template <isArithmetic Q> constexpr Q abs(const Q& lhs) { return Q(std::abs(getInternal(lhs))); }
template <isQuantity Q> constexpr Q abs(const Q& lhs) { return Q(std::abs(lhs.internal())); }

template <isArithmetic Q, isArithmetic R> constexpr Q max(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q max(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return (lhs > rhs ? lhs : rhs);
}

template <isArithmetic Q, isArithmetic R> constexpr Q min(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q min(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return (lhs < rhs ? lhs : rhs);
Expand All @@ -440,77 +440,73 @@ constexpr double sgn(double lhs) {
return lhs;
}

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

template <int R, isArithmetic Q, isArithmetic S = Exponentiated<Q, std::ratio<R>>> constexpr S pow(const Q& lhs) {
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));
}

template <isArithmetic Q, isArithmetic S = Exponentiated<Q, std::ratio<2>>> constexpr S square(const Q& lhs) {
template <isQuantity Q, isQuantity S = Exponentiated<Q, std::ratio<2>>> constexpr S square(const Q& lhs) {
return pow<2>(lhs);
}

template <isArithmetic Q, isArithmetic S = Exponentiated<Q, std::ratio<3>>> constexpr S cube(const Q& lhs) {
template <isQuantity Q, isQuantity S = Exponentiated<Q, std::ratio<3>>> constexpr S cube(const Q& lhs) {
return pow<3>(lhs);
}

template <int R, isArithmetic Q, isArithmetic S = Rooted<Q, std::ratio<R>>> constexpr S root(const Q& lhs) {
template <int R, isQuantity Q, isQuantity S = Rooted<Q, std::ratio<R>>> constexpr S root(const Q& lhs) {
return S(std::pow(lhs.internal(), 1.0 / R));
}

template <isArithmetic Q, isArithmetic S = Rooted<Q, std::ratio<2>>> constexpr S sqrt(const Q& lhs) {
return root<2>(lhs);
}
template <isQuantity Q, isQuantity S = Rooted<Q, std::ratio<2>>> constexpr S sqrt(const Q& lhs) { return root<2>(lhs); }

template <isArithmetic Q, isArithmetic S = Rooted<Q, std::ratio<3>>> constexpr S cbrt(const Q& lhs) {
return root<3>(lhs);
}
template <isQuantity Q, isQuantity S = Rooted<Q, std::ratio<3>>> constexpr S cbrt(const Q& lhs) { return root<3>(lhs); }

template <isArithmetic Q, isArithmetic R> constexpr Q hypot(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q hypot(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return Q(std::hypot(lhs.internal(), rhs.internal()));
}

template <isArithmetic Q, isArithmetic R> constexpr Q mod(const Q& lhs, const R& rhs) {
template <isQuantity Q, isQuantity R> constexpr Q mod(const Q& lhs, const R& rhs) {
return Q(std::fmod(lhs.internal(), rhs.internal()));
}

template <isArithmetic Q, isArithmetic R> constexpr Q remainder(const Q& lhs, const R& rhs) {
template <isQuantity Q, isQuantity R> constexpr Q remainder(const Q& lhs, const R& rhs) {
return Q(std::remainder(lhs.internal(), rhs.internal()));
}

template <isArithmetic Q1, isArithmetic Q2> constexpr Q1 copysign(const Q1& lhs, const Q2& rhs) {
template <isQuantity Q1, isQuantity Q2> constexpr Q1 copysign(const Q1& lhs, const Q2& rhs) {
return Q1(std::copysign(lhs.internal(), rhs.internal()));
}

template <isArithmetic Q> constexpr bool signbit(const Q& lhs) { return std::signbit(lhs.internal()); }
template <isQuantity Q> constexpr bool signbit(const Q& lhs) { return std::signbit(lhs.internal()); }

template <isArithmetic Q, isArithmetic R, isArithmetic S> constexpr Q clamp(const Q& lhs, const R& lo, const S& hi)
template <isQuantity Q, isQuantity R, isQuantity S> constexpr Q clamp(const Q& lhs, const R& lo, const S& hi)
requires Isomorphic<Q, R, S>
{
return Q(std::clamp(lhs.internal(), lo.internal(), hi.internal()));
}

template <isArithmetic Q, isArithmetic R> constexpr Q ceil(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q ceil(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return Q(std::ceil(lhs.internal() / rhs.internal()) * rhs.internal());
}

template <isArithmetic Q, isArithmetic R> constexpr Q floor(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q floor(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return Q(std::floor(lhs.internal() / rhs.internal()) * rhs.internal());
}

template <isArithmetic Q, isArithmetic R> constexpr Q trunc(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q trunc(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return Q(std::trunc(lhs.internal() / rhs.internal()) * rhs.internal());
}

template <isArithmetic Q, isArithmetic R> constexpr Q round(const Q& lhs, const R& rhs)
template <isQuantity Q, isQuantity R> constexpr Q round(const Q& lhs, const R& rhs)
requires Isomorphic<Q, R>
{
return Q(std::round(lhs.internal() / rhs.internal()) * rhs.internal());
Expand Down

0 comments on commit ad56124

Please sign in to comment.