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 524 of file math8.h.

524 {
525 if (x <= 1) {
526 return x;
527 }
528
529 uint8_t low = 1; // lower bound
530 uint8_t hi, mid;
531
532 if (x > 7904) {
533 hi = 255;
534 } else {
535 hi = (x >> 5) + 8; // initial estimate for upper bound
536 }
537
538 do {
539 mid = (low + hi) >> 1;
540 if ((uint16_t)(mid * mid) > x) {
541 hi = mid - 1;
542 } else {
543 if (mid == 255) {
544 return 255;
545 }
546 low = mid + 1;
547 }
548 } while (hi >= low);
549
550 return low - 1;
551}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80

References LIB8STATIC, and x.

Referenced by rgb2hsv_approximate(), and sqrt8().

+ Here is the caller graph for this function: