6 days, 23 hours ago.
Calculation always evaluates to 0
in the code snippet below, both gain_range and gain_SYSTEM are declared as float earlier in the program.
However, both gain_calc and volume_display always evaluate to 0. I can only get a non zero (and correct answer) if I remove the division in the gain_calc formula.
Any ideas about what I am doing wrong?
gain_range = (rint(gain_SYSTEM)) - vol_min; gain_calc = ((lr_volume - vol_min)/gain_range)*16; //((lr_volume - vol_min)/gain_range)*16; volume_display = rint(gain_calc); //normalized count out of 16 printf("gain_calc = %f gain range %d lr_volume %d vol_disp %d \n\r",gain_calc, gain_range, lr_volume, volume_display); vol_disp();
6 days, 22 hours ago.
- Try to first multiply and then divide when calculating
gain_calc = ((lr_volume - vol_min)*16.0f)/gain_range;
To post an answer, please log in.