4 ms·
"I’m also not aware of any calculator (or programming language) that currently works this way." [represent fractions exactly wherever reasonable to do so] This
by learnstats2 7y ago
"I’m also not aware of any calculator (or programming language) that currently works this way." [represent fractions exactly wherever reasonable to do so]
This is surprising to me!
Casio scientific calculators definitely do this, and have done for many years now. And Casio (it appears) also represents pi and square roots exactly/symbolicly, wherever it's reasonable to do so.
- phs2501 7y agoYeah, they just lack exposure to systems that do: :; sbcl This is SBCL 1.5.5, an implementation of ANSI Common Lisp. ... * (/ 1 3) 1/3
- gumby 7y agoTo be fair that is a pretty recent addition to Lisp, only added in the late 1970s. They might not be keeping up with the latest stuff.
- BiteCode_dev 7y agoI know that in Python, you can do: >>> import fractions >>> from fractions import Fraction as F >>> F(3, 17) * F(12, 5) + F(56, 99) Fraction(8324, 8415) >>> F(3, 17) * F(12, 5) + F(56, 99) / 3 + 2 * 4 Fraction(217412, 25245) However, if you use a float or a complex with it, the fraction get resolved: >>> F(217412, 25245) + 0.1 8.712081600316894 >>> F(217412, 25245) + 1j (8.612081600316895+1j) You also have some constants: >>> import math >>> math.pi 3.141592653589793 >>> math.e 2.718281828459045 But they are not just symbol, there is a precision-limited value behind it. Although the value seems to match the precision NASA considers to be enough for trajectories of spacecrafts like Voyager: https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/ https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimal...
- EricRiese 7y agoRaku Perl 6 uses rationals by default for decimal literals. No imports necessary. You actually have to opt-in to floating point by using engineering notation. https://docs.perl6.org/language/numerics#Rational https://docs.perl6.org/language/numerics#Rational
- jwmerrill 7y ago> "I’m also not aware of any calculator (or programming language) that currently works this way." [represent fractions exactly wherever reasonable to do so] Author here. The paraphrase makes this sound wrong, but what I actually meant is that I don’t know of any calculator that uses rationals while the numerator and denominator can be represented as integer floating point doubles, and then falls back to a single floating point double if the numerator or denominator overflow. I am aware of many systems that use arbitrary precision rationals, and I mentioned this in the post: > Rational numbers where the numerator and denominator are allowed to grow arbitrarily large are used by computer algebra systems (CAS) like Mathematica and Maple (and also some high-end handheld graphing calculators).