4 ms·
Julia has built in rationals (as do a few other languages). I'm not aware of any language (other than Wolfram) that defaults to storing something like 0.1 as 1
by twtw 8y ago
Julia has built in rationals (as do a few other languages).
I'm not aware of any language (other than Wolfram) that defaults to storing something like 0.1 as 1/10 - i.e. uses the decimal constant notation for rationals, rather than having some secondary syntax or library.
- rurban 8y agoIn Common Lisp it's even standardized. Arithmetic is too important to be left to wrong CPU intrinsics.
- kccqzy 8y agoEven in Wolfram, 0.1 is not the same as 1/10. In[1]:= Precision[0.1] Out[1]= MachinePrecision In[2]:= Precision[1/10] Out[2]= \[Infinity]
- twtw 8y agoAh, thanks for the correction. I don't currently have a license, so out of curiosity is 0.3 == 3/10 in wolfram?
- kccqzy 8y agoYes that's true. According to the documentation of Equal†, > Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits). Which is why in Mathematica, 0.1+0.2==0.3 is also True. If you need a kind of equality comparison that returns False for 0.3 and 3/10, use SameQ. Funnily, SameQ[0.1+0.2,0.3] is also True, because SameQ allows two machine precision numbers to differ in their last binary digit. †: https://reference.wolfram.com/language/ref/Equal.html https://reference.wolfram.com/language/ref/Equal.html
- sgt101 8y agoYes, but the Julia REPL produces 2.0 as an answer and casting both these to BigInt doesn't work either.
- twtw 8y agoThus my second paragraph. You have to opt in to use other formats. Casting to bigint doesn't work because the problem occurs when converting the decimal constant in the source to floating point. You would have to convince the parser to parse the constant as something besides a float.
- sgt101 8y agoAgree - but it's a shame, fundamentally what ever the reason this is really, really egregious behaviour