FastLED 3.10.8
Loading...
Searching...
No Matches

◆ sqrt_newton_()

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

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

233 {
234 if (value <= F(0)) return F(0);
235 // Initial estimate: x_0 = value / 2. Pure-arithmetic, no bit-cast needed.
236 // Newton converges quadratically so 5-6 iterations is plenty even from a
237 // crude start.
238 F x = value;
239 if (x > F(1)) x = F(1) + (x - F(1)) * F(0.5); // bias toward 1 for fast convergence
240 for (int i = 0; i < 6; ++i) {
241 if (x == F(0)) break;
242 x = F(0.5) * (x + value / x);
243 }
244 return x;
245}
constexpr int type_rank< T >::value

References fl::FL_NO_EXCEPT, 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: