10-17-2017, 11:50 AM
It is a problem with floating-point numbers in any programming language. Not all numbers can be stored with exact value. For example, how to store numbers with infinite number of digits after the decimal point, for example the result of 1/3 is 0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333....... Operations with double numbers then produce the nearest number that can be stored in the variable. After one or several such operations the result can become incorrect, therefore the >= operator does not work as expected.
Macro Macro1053
Macro Macro1053
out
double multiple=0.95
rep 100
,;out multiple
,out "%.20f" multiple ;;shows the number with higher precision than 'out multiple'
,if multiple>=5.15
,,out "yes"; break
,out "no"
,multiple=multiple+0.35
;You see, the number then is 5.1499999999999995 instead of 5.15.
;Even the initial number cannot be stored in the variable. Instead of 0.95 it is 0.94999999999999996.