Fast 8-bit “percentage” function
This function optimizes its runtime performance by substituting the division by 255 with an approximation using bitshifts.
Nonetheless, its result are as accurate as a floating point division with 64-bit precision.
percentage as the number of 255ths (“two hundred fifty-fifths”)
base value (“total”)
round(value * nPercentage / 255.0)
See Implementation
Fast 8-bit “percentage” function
This function optimizes its runtime performance by substituting the division by 255 with an approximation using bitshifts.
Nonetheless, its result are as accurate as a floating point division with 64-bit precision.