Is there a better way in C or C++, or just mathematically in general, to map ratios of numbers while preserving or rounding data?
Take the following example
double cdp = 17000.0;
float integ = 30000.0 / 255;
int val = cdp / integ;
color = color + RGB(val, val, val);
Here I want to map a range of numbers [0, 30000] to a value [0, 255]
Multiply by 255 then divide by 30000. Use an integer format that can hold the product of your two range limits, 30000*255 or 7.65 million. This avoids the precision issues with intermediate floating point values.