4 ms·
In Python 0.1 + 0.2 is not equal to 0.3 because the result is 0.30000000000000004. In R 0.1 + 0.2 is equal to 0.3.
by darkhorn 8y ago
In Python 0.1 + 0.2 is not equal to 0.3 because the result is 0.30000000000000004.
In R 0.1 + 0.2 is equal to 0.3.
- detaro 8y agoR: > 0.1+0.2 == 0.3 [1] FALSE ?
- darkhorn 8y agoWhy do you compare point to point, it is meaningless? The result for 0.1 + 0.2 shows 0.3. It doesn't show you wrong result. If you print it prints 0.3, nothing else. Why do you compare point to point? I have never once in my Statistics education compared point to point. You always need to see the probability of the result if it is within 2 points. But if you want to compare use all.equal(0.1 + 0.2, 0.3)
- detaro 8y agoI thought that's what you mean by "equal". It didn't appear to me that you were merely talking about the default formatting of numbers printed on the REPL, which is utterly inconsequential to developing and porting applications.
- darkhorn 8y agoR is not used for developing applications. https://www.r-project.org/about.html https://www.r-project.org/about.html
- detaro 8y agoThis entire subthread is under a comment talking about "productionalizing" code developed in R. If you want to make an argument that R should not be used to make products, but only as an interactive notebook and to make nice plots, maybe make that instead of just mentioning small UI details.
- sampo 8y agoNot on my R: > (0.1 + 0.2) == 0.3 [1] FALSE
- darkhorn 8y agoThe result for 0.1 + 0.2 is 0.3. https://imgur.com/xWpx1Cg https://imgur.com/xWpx1Cg Why do you compare point to point? I have never once in my Statistics education compared point to point. You always need to see the probability of the result if it is within 2 points. But if you want to compare use all.equal(0.1 + 0.2, 0.3)
- sampo 8y ago> all.equal(0.1 + 0.2 + 0.000000003, 0.3) [1] TRUE
- j7ake 8y agoTry this: > print(.1+.2, digits=18) [1] 0.300000000000000044
- darkhorn 8y agoIn R 0.1 + 0.2 returns 0.3. In Python 0.1 + 0.2 returns 0.30000000000000004 Why do you compare point to point? I have never once in my Statistics education compared point to point. You always need to see the probability of the result if it is within 2 points. But if you want to compare use all.equal(0.1 + 0.2, 0.3)
- dekhn 8y agoNot only is this technically wrong, but Python has a decimal module for performing these kinds of calculations. It uses floats/doubles for the native float type which produces exactly the type of results you see above.
- darkhorn 8y agoWhat is the result of 3/2? In R it is 0.5. In Python it is 1.