4 ms·
Anyone know of a comparison of the linked paper's algorithm to how Gavin Howard's 'bc' CLI calculator does it?
by dgacmu 2y ago
Anyone know of a comparison of the linked paper's algorithm to how Gavin Howard's 'bc' CLI calculator does it?
- tialaramex 2y agoSo, 'bc' just has the (big) rationals. Rationals are the numbers you could make by taking one integer (say 5 or minus sixteen trillion and fifty-one) and dividing it by some positive integer (such as three or sixty-two thousand) If we have a "Big Integer" type which can represent arbitrarily huge integers, such 10 to the power 5000, we can use two of these to make a Big Rational, and so that's what bc has. But the rationals aren't enough for all the features on your calculator. What's the square root of ten ? How about the square root of 40 ? Now, multiply those together. The correct answer is 20. Not 20.00000000000000001 but exactly 20.
- dgacmu 2y agoAhh, thank you. Yes indeed: bc says: >>> sqrt(10) * sqrt(10) 9.99999999999999999994 Android calculator, on the other hand, gets this one right.
- gavinhoward 2y agoGavin Howard here. Yes, GP is entirely correct. I want to do something like the article, but the bc standard (POSIX) requires a decimal BigInteger representation. I am glad you like my bc!
- tialaramex 2y agoI actually use bc a lot and the fact it's just the big rationals was annoying which is why I set off on the route that ended with my crate `realistic` Amusingly one of the things I liked in bc was that I could write stuff like sqrt(10) * sqrt(40) and it works -- but even the more-bc-like command line toy for my own use doesn't do this, turns out a few months of writing the guts of a computable reals implementation makes (* (sqrt 10) (sqrt 40)) seem like a completely reasonable way to write what I meant and so "Make it work like bc" faded from "Important" to "Eh, whatever I'll get to it later". If you'd asked me a year ago if "fix edge case bugs in converting realistic::Real to f64" would happen before "Have natural expressions like 1 + 2 * 3 do what is expected" I'd have said not a chance, but shows how much I knew.