FastLED 3.10.6
Loading...
Searching...
No Matches

◆ sqrt_newton_()

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

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

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