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

◆ isqrt32_ceil()

fl::i32 fl::gfx::detail::isqrt32_ceil ( fl::i32 n)
inline

Integer square root using Newton iteration Computes ceil(sqrt(n)) for positive integers More accurate than digit-by-digit for the ceiling case.

Definition at line 30 of file integer_math.h.

30 {
31 if (n <= 0) return 0;
32 fl::u32 x = (fl::u32)n;
33 fl::u32 s = 1u << 16; // initial guess: sqrt(2^32) = 2^16
34 for (int i = 0; i < 8; ++i) { // 8 iterations converges for 32-bit input
35 s = (s + x / s) >> 1; // Newton iteration: s = (s + n/s) / 2
36 }
37 return (fl::i32)s;
38}

References fl::x.