Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by ezfe on Wednesday February 08, 2023 @01:54PM
(#34712883)
Numbers (from Apple) returns TRUE for both expressions you list
[ Parent
| on HN ]
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by Kon-Peki on Wednesday February 08, 2023 @02:27PM
(#34713462)
Objective-C has a really nice decimal math library. Last I looked (it’s been a while), Swift didn’t. It might have one by now.
Years ago, I had a few apps in the App Store that made extensive use of it. It really was very nice to work with.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by arcticbull on Wednesday February 08, 2023 @02:51PM
(#34713870)
Swift has the same functionality in the Decimal type.
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by Kon-Peki on Wednesday February 08, 2023 @03:15PM
(#34714273)
Thanks! It looks like that was added in Swift 3. That was a long time ago. I guess I’m just really old ;)
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by sheetjs on Wednesday February 08, 2023 @02:17PM
(#34713287)
Under the hood, modern Numbers stores values in Decimal128 (16 bytes)
Re:Why does 0.1 and 0.2 = 0.30000000000000004?
by Salgat on Wednesday February 08, 2023 @04:35PM
(#34715576)
So people understand, Decimal type is not fixed point, but rather is a floating-point type that uses base 10 instead base 2. This means that if you do 1.0/3.0*3.0, you still get 0.999999~.
Example: http://tpcg.io/_A0IXQJ