FastLED 3.9.15
Loading...
Searching...
No Matches

◆ sqrt_newton_()

template<typename F>
F fl::detail::sqrt_newton_ ( F value)
inline

Definition at line 151 of file math.cpp.hpp.

151 {
152 if (value <= F(0)) return F(0);
153 // Initial estimate: x_0 = value / 2. Pure-arithmetic, no bit-cast needed.
154 // Newton converges quadratically so 5-6 iterations is plenty even from a
155 // crude start.
156 F x = value;
157 if (x > F(1)) x = F(1) + (x - F(1)) * F(0.5); // bias toward 1 for fast convergence
158 for (int i = 0; i < 6; ++i) {
159 if (x == F(0)) break;
160 x = F(0.5) * (x + value / x);
161 }
162 return x;
163}
constexpr int type_rank< T >::value

References FL_NOEXCEPT, fl::type_rank< T >::value, and fl::x.

Referenced by fl::asin_impl_double(), fl::asin_impl_float(), fl::hypot_impl_double(), fl::hypot_impl_float(), fl::sqrt_impl_double(), and fl::sqrt_impl_float().

+ Here is the caller graph for this function: