Floating point classification functions

Add the ability for `isnan`, `isfinite`, and `isinf` to work on dimensioned quantities.
This commit is contained in:
Nick Thompson committed 2023-12-16 08:08:44 -08:00
1 parent ffba606115
commit 7a270a6fd9
3 files changed
+63

No files matched your search

+47
View File
@@ -136,6 +136,53 @@ template<auto R, typename Rep>
return {static_cast<Rep>(abs(q.numerical_value_ref_in(q.unit))), R};
}
/**
* @brief Determines if a number is finite.
*
* @param a: Number to analyze.
* @return bool: Whether the number is finite or not.
*/
template<auto R, typename Rep>
[[nodiscard]] constexpr bool isfinite(const quantity<R, Rep>& a) noexcept
requires(
requires { isfinite(a.numerical_value_ref_in(a.unit)); } ||
requires { std::isfinite(a.numerical_value_ref_in(a.unit)); })
{
using std::isfinite;
return isfinite(a.numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a number is infinite.
*
* @param a: Number to analyze.
* @return bool: Whether the number is infinite or not.
*/
template<auto R, typename Rep>
[[nodiscard]] constexpr bool isinf(const quantity<R, Rep>& a) noexcept
requires(
requires { isinf(a.numerical_value_ref_in(a.unit)); } || requires { std::isinf(a.numerical_value_ref_in(a.unit)); })
{
using std::isinf;
return isinf(a.numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a number is a nan.
*
* @param a: Number to analyze.
* @return bool: Whether the number is a NaN or not.
*/
template<auto R, typename Rep>
[[nodiscard]] constexpr bool isnan(const quantity<R, Rep>& a) noexcept
requires(
requires { isnan(a.numerical_value_ref_in(a.unit)); } || requires { std::isnan(a.numerical_value_ref_in(a.unit)); })
{
using std::isnan;
return isnan(a.numerical_value_ref_in(a.unit));
}
/**
* @brief Computes the fma of 3 quantities
*