Please, help me to solve the problem: <source code> bit Result; float Density; Density = 0.55; if(( Density < 0.54999995) { Result = 0; } else { Result = 1; } While after running this code Result = 0 ?
Insufficient precision! 0.54999995 is pretty damn close to 0.55, isn't it!
0.54999995 == 0.55 - maybe. But why 0.54999995 > 0.55 ?
In the debugger, look at the raw binary representations of these numbers.
why do you float? store the value *100, take care of the decimal point in the presentation. Your program will compact and speed up and you will smile like the cheshire cat. Erik
0.55 - 3F 0C CC CD 0.54999995 - 3F 0C CC CC Why 0.55 < 0.54999995 ? I don't understand
Look at bits to round for float compare in C51 options. Default is 3.
The default setting for FLOATFUZZY is 3-bits. This means bits are rounded before comparisons. Set this to 0 and you'll get the results you're looking for. Jon
The down side of setting it to 0 is that the equal comparison will not work very well.
2 Jon, Neil Thank you very mach. All OK!