| 149 | // space and rotational math. |
| 150 | template <typename F> |
| 151 | inline 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 | // |