added support for isfinite isinf and isnan on instances of quantity_point

This commit is contained in:
Yves Delley
2024-05-10 20:05:36 +02:00
parent 15404cd3a7
commit ddbdd6a4c2

View File

@@ -25,6 +25,7 @@
#include <mp-units/bits/module_macros.h>
#include <mp-units/framework/customization_points.h>
#include <mp-units/framework/quantity.h>
#include <mp-units/framework/quantity_point.h>
#include <mp-units/framework/unit.h>
#include <mp-units/framework/value_cast.h>
@@ -130,10 +131,10 @@ template<auto R, typename Rep>
}
/**
* @brief Determines if a number is finite.
* @brief Determines if a quantity is finite.
*
* @param a: Number to analyze.
* @return bool: Whether the number is finite or not.
* @param a: Quantity to analyze.
* @return bool: Whether the quantity is finite or not.
*/
template<auto R, typename Rep>
requires requires(Rep v) { isfinite(v); } || requires(Rep v) { std::isfinite(v); }
@@ -144,10 +145,24 @@ template<auto R, typename Rep>
}
/**
* @brief Determines if a number is infinite.
* @brief Determines if a quantity point is finite.
*
* @param a: Number to analyze.
* @return bool: Whether the number is infinite or not.
* @param a: Quantity point to analyze.
* @return bool: Whether the quantity point is finite or not.
*/
template<auto R, auto PO, typename Rep>
requires requires(Rep v) { isfinite(v); } || requires(Rep v) { std::isfinite(v); }
[[nodiscard]] constexpr bool isfinite(const quantity_point<R, PO, Rep>& a) noexcept
{
using std::isfinite;
return isfinite(a.quantity_ref_from(a.point_origin).numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a quantity is infinite.
*
* @param a: Quantity to analyze.
* @return bool: Whether the quantity is infinite or not.
*/
template<auto R, typename Rep>
requires requires(Rep v) { isinf(v); } || requires(Rep v) { std::isinf(v); }
@@ -157,12 +172,26 @@ template<auto R, typename Rep>
return isinf(a.numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a quantity point is infinite.
*
* @param a: Quantity point to analyze.
* @return bool: Whether the quantity point is infinite or not.
*/
template<auto R, auto PO, typename Rep>
requires requires(Rep v) { isinf(v); } || requires(Rep v) { std::isinf(v); }
[[nodiscard]] constexpr bool isinf(const quantity_point<R, PO, Rep>& a) noexcept
{
using std::isinf;
return isinf(a.quantity_ref_from(a.point_origin).numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a number is a nan.
* @brief Determines if a quantity is a nan.
*
* @param a: Number to analyze.
* @return bool: Whether the number is a NaN or not.
* @param a: Quantity to analyze.
* @return bool: Whether the quantity is a NaN or not.
*/
template<auto R, typename Rep>
requires requires(Rep v) { isnan(v); } || requires(Rep v) { std::isnan(v); }
@@ -172,6 +201,21 @@ template<auto R, typename Rep>
return isnan(a.numerical_value_ref_in(a.unit));
}
/**
* @brief Determines if a quantity point is a nan.
*
* @param a: Quantity point to analyze.
* @return bool: Whether the quantity point is a NaN or not.
*/
template<auto R, auto PO, typename Rep>
requires requires(Rep v) { isnan(v); } || requires(Rep v) { std::isnan(v); }
[[nodiscard]] constexpr bool isnan(const quantity_point<R, PO, Rep>& a) noexcept
{
using std::isnan;
return isnan(a.quantity_ref_from(a.point_origin).numerical_value_ref_in(a.unit));
}
/**
* @brief Computes the fma of 3 quantities
*