Treimin Clark wrote:Look at the following statements and outputs:
I'm sure sure, these type questions are not in the exam.
As programmers, we must understand that floating-point representation is not exact. Some values, such as 0.25 (1/4) or 0.375 (3/8)--notice the powers of two in the denominators, can be represented exactly but most cannot. Not surprisingly, 0.1 (1/10) is one of those than cannot.
Read the links to which Mr. Wong refers. They are good.
As for these examples, try adding on a small delta value before performing the remainder operation. Without the inexactness, we would expect the remainer to be equal to the delta value. With the inexactness it is merely close:
Where a value is over the delta, the original result (without the delta) was a small positive value.
Where a value is under the delta, the original result was just a smidgen under 1.1.
(Well not precisely because of the inexactness, but you get the idea.)