It is customary to use = when determining whether two quantities are equal, but such use involves a great risk. Let's look at an example.
1 nominal = 1.0 2 sum = 0.0 3 4 for I = 1, 10 do 5 sum = sum + 0.1 6 end 7 8 print (nominal = sum, nominal, sum) 9 10 11 12 x = 113 y = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.114 + 1.015 z = 16 print (x = y, x = z, y = z, x, y, z)
Guess what the output is, which are true and false. Run
Furthermore, we can know that the result of x-y> 0 is true, which is rather confusing. It only accumulates 10 times, and 0.1 is not a very extreme value. It can only be sighed. If you are interested, try the results in C ++ and java.
A better way is to write the equality judgment function by yourself. The value variable can determine whether the difference value should be equal by itself. This conclusion should be kept in mind. Remember to use it later, or the bug will be very depressing.