We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am experiencing unexpected results when performing floating point arithmetic.
void main( void ) { long raw_value; float scaling_factor = 0.0762951; float scaling_offset = -1000; float result; for( raw_value = 65530; raw_value <= 65535; raw_value++ ) { result = ( raw_value * scaling_factor ) + scaling_offset; } }
I tried your code using C51 v7.01 and it worked correctly. What version are you using? I output the results through the serial port with:
printf("\nraw=%ld result=%.3f",raw_value,result);