12namespace autopas::utils::ConstexprMath {
22constexpr typename std::enable_if_t<std::is_floating_point_v<T>, T>
sqrt(T x, T epsilon) {
23 if (x >= 0 and x < std::numeric_limits<T>::infinity()) {
27 while ((xn - prev < 0 ? prev - xn : xn - prev) > epsilon) {
29 T xn1 = 0.5 * (xn + x / xn);
34 return std::numeric_limits<T>::quiet_NaN();
45constexpr typename std::enable_if_t<std::is_integral_v<T>, T>
sqrt(T x) {
52 T x1 = (x0 + x / x0) / 2;
55 x1 = (x0 + x / x0) / 2;
59 throw std::invalid_argument(
"Negative number passed.");
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > sqrt(T x, T epsilon)
Calculates the square root of floating point values x based on Newton-Raphson methon.
Definition: ConstexprMath.h:22