MCPcopy Create free account
hub / github.com/FastLED/FastLED / sqrt_newton_

Function sqrt_newton_

src/fl/math/math.cpp.hpp:151–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149// space and rotational math.
150template <typename F>
151inline F sqrt_newton_(F value) FL_NOEXCEPT {
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}
164
165// --- Polynomial sin/cos with range reduction ------------------------------
166//

Callers

nothing calls this directly

Calls 1

FClass · 0.85

Tested by

no test coverage detected