Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for quantity_point math #570

Merged
merged 2 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 50 additions & 9 deletions src/core/include/mp-units/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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); }
Expand All @@ -144,10 +145,23 @@ 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(quantity<R, Rep> q) { isfinite(q); }
[[nodiscard]] constexpr bool isfinite(const quantity_point<R, PO, Rep>& a) noexcept
{
return isfinite(a.quantity_ref_from(a.point_origin));
}

/**
* @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); }
Expand All @@ -157,12 +171,25 @@ 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(quantity<R, Rep> q) { isinf(q); }
[[nodiscard]] constexpr bool isinf(const quantity_point<R, PO, Rep>& a) noexcept
{
return isinf(a.quantity_ref_from(a.point_origin));
}


/**
* @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); }
Expand All @@ -172,6 +199,20 @@ 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(quantity<R, Rep> q) { isnan(q); }
[[nodiscard]] constexpr bool isnan(const quantity_point<R, PO, Rep>& a) noexcept
{
return isnan(a.quantity_ref_from(a.point_origin));
}

/**
* @brief Computes the fma of 3 quantities
*
Expand Down
Loading