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

◆ sqrt16()

LIB8STATIC uint8_t sqrt16 ( uint16_t x)

Square root for 16-bit integers.

About three times faster and five times smaller than Arduino's general sqrt on AVR.

Definition at line 540 of file math8.h.

540 {
541 if (x <= 1) {
542 return x;
543 }
544
545 uint8_t low = 1; // lower bound
546 uint8_t hi, mid;
547
548 if (x > 7904) {
549 hi = 255;
550 } else {
551 hi = (x >> 5) + 8; // initial estimate for upper bound
552 }
553
554 do {
555 mid = (low + hi) >> 1;
556 if ((uint16_t)(mid * mid) > x) {
557 hi = mid - 1;
558 } else {
559 if (mid == 255) {
560 return 255;
561 }
562 low = mid + 1;
563 }
564 } while (hi >= low);
565
566 return low - 1;
567}
int x
Definition simple.h:92

References LIB8STATIC, and x.

Referenced by rgb2hsv_approximate(), and sqrt8().

+ Here is the caller graph for this function: