FastLED 3.10.8
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 386 of file power_mgt.cpp.hpp.

386 {
387 if (num >= den) {
388 return 255;
389 }
390 fl::u32 q = 0;
391 fl::u32 r = num;
392 for (fl::u8 bit = 0; bit < 8; ++bit) {
393 q <<= 1;
394 if (r >= den - r) {
395 r -= den - r;
396 q |= 1;
397 } else {
398 r += r;
399 }
400 }
401 return r >= num ? q : q - 1;
402}
unsigned char u8
Definition stdint.h:131

References FL_NO_EXCEPT.

Referenced by brightness_within_budget().

+ Here is the caller graph for this function: