.125 + .375 == .5
You should be using == for floats when they're actually equal. 0.1 just isn't an actual number.
You should be using == for floats when they're actually equal. 0.1 just isn't an actual number.
> 1.25 * 0.1
0.1250000000000000069388939039Yes.
1.25 = 2^0 + 2^-2, so is representable.
0.125 = 2^-3, so is representable
1.25 / 10.0 = 0.125 so is representable. 10.0 = 2^3 + 2^1.
1.25 * 0.1 is not representable, because 0.1 is not representable, and those low order bits show up in the multiplication
A finitist computer scientists only accepts those numbers as real that can be expressed exactly in finite base-two floating point?
0.1 is just as non-representable in floating point as is pi as is 100^100 in a 32 bit integer.
Terminating dyadic rationals (up to limits based on float size) are the representable values.