mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
feat: fma
for quantity points added
This commit is contained in:
@@ -237,6 +237,29 @@ template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
|||||||
common_reference(R * S, T)};
|
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.
|
* @brief Computes the floating-point remainder of the division operation x / y.
|
||||||
|
Reference in New Issue
Block a user