3 ms·
The entire intrigue of the opening paragraph is the claim: > there’s a floating point number that’s closer to 0.3 than 0.30000000000000004! But then you read
by raldi 4y ago
The entire intrigue of the opening paragraph is the claim:
> there’s a floating point number that’s closer to 0.3 than 0.30000000000000004!
But then you read to the end and find out this wasn’t true, and the answer to the clickbait headline is just, “Because it’s the closest floating-point value to the correct answer”.
- topaz0 4y agoYou're mistaken. In fact 0.3 is closer to the next-smaller float than it is to the next-larger one which results. But the result of float(0.1) + float(0.2) is not any of those things, but rather halfway between the previous and next floats from 0.3, so it gets rounded up instead of down.