FastLED 3.10.10
Loading...
Searching...
No Matches

◆ power_ratio_of_255()

fl::u32 power_ratio_of_255 ( fl::u32 num,
fl::u32 den )

min(255, floor(255 * num / den)) for den > 0, computed in 32-bit arithmetic.

The limiter's brightness ratio; declared for its tests.

Definition at line 408 of file power_mgt.cpp.hpp.

408 {
409 if (num >= den) {
410 return 255;
411 }
412 fl::u32 q = 0;
413 fl::u32 r = num;
414 for (fl::u8 bit = 0; bit < 8; ++bit) {
415 q <<= 1;
416 if (r >= den - r) {
417 r -= den - r;
418 q |= 1;
419 } else {
420 r += r;
421 }
422 }
423 return r >= num ? q : q - 1;
424}
unsigned char u8
Definition stdint.h:132

References FL_NO_EXCEPT.

Referenced by brightness_within_budget().

+ Here is the caller graph for this function: