feat: fma for quantity points added

This commit is contained in:
Mateusz Pusz
2024-05-29 19:54:53 +02:00
parent 411d7d5c50
commit da0ab13b0d

View File

@@ -237,6 +237,29 @@ template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
common_reference(R * S, T)};
}
/**
* @brief Computes the fma of 2 quantities and a quantity point
*
* @param a: Multiplicand
* @param x: Multiplicand
* @param b: Addend
* @return QuantityPoint: The nearest floating point representable to ax+b
*/
template<auto R, auto S, auto T, auto Origin, typename Rep1, typename Rep2, typename Rep3>
requires requires { common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
(get_unit(R) * get_unit(S) == get_unit(T)) && requires(Rep1 v1, Rep2 v2, Rep3 v3) {
requires requires { fma(v1, v2, v3); } || requires { std::fma(v1, v2, v3); };
}
[[nodiscard]] constexpr QuantityPointOf<
common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S),
get_quantity_spec(T))> auto fma(const quantity<R, Rep1>& a, const quantity<S, Rep2>& x,
const quantity_point<T, Origin, Rep3>& b) noexcept
{
using std::fma;
return Origin + quantity{fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit),
b.quantity_ref_from(b.point_origin).numerical_value_ref_in(b.unit)),
common_reference(R * S, T)};
}
/**
* @brief Computes the floating-point remainder of the division operation x / y.