17 ms·
“A calculator app? Anyone could make that”
- morkalork 2y agoThis reminds me of solving project Euler problems that intentionally not possible to solve with simple float representation of numbers
- coder543 2y agoThe link at the end is both shortened (for tracking purposes?) and unclickable… so that’s unfortunate. Here is the real link to the paper, in a clickable format: https://dl.acm.org/doi/pdf/10.1145/3385412.3386037 https://dl.acm.org/doi/pdf/10.1145/3385412.3386037
- ChadNauseam 2y agoThanks for pointing that out. It should be fixed now. The shortening was done by the editor I was using ("Buffer") to draft the tweets in - I wasn't intending to track one but it probably does provide some means of seeing how many people clicked the link
- est 2y agoif "answer" overflows, switch to symbolic mode.
- anon-3988 2y agonot that simple, 1/3 + 5 - 1/3 should be 5. It doesn't overflow in IEEE754
- coder543 2y agoThat does appear to equal exactly 5... would you care to show how it doesn't? $ cat check_math.c #include <stdio.h> int main() { // Define the values as float (32-bit floating point) float one_third = 1.0f / 3.0f; float five = 5.0f; // Compute the equation float result = one_third + five - one_third; // Check for exact equality if (result == five) { printf("The equation evaluates EXACTLY to 5.0 (True)\n"); } else { // Print the actual result and the difference printf("The equation does NOT evaluate exactly to 5.0 (False)\n"); printf("Computed result: %.10f\n", result); printf("Difference: %.10f\n", result - five); } return 0; } $ gcc -O0 check_math.c -o check_math; ./check_math The equation evaluates EXACTLY to 5.0 (True)
- anon-3988 2y agoOkay..that was just an example (and a false one apparently). Its easy enough to find an example where your typical FP operations doesn't work out. https://godbolt.org/z/Mr4Ez8xz1 https://godbolt.org/z/Mr4Ez8xz1
- roenxi 2y ago> And almost all numbers cannot be expressed in IEEE floating points. It is a bit stronger than that. Almost all numbers cannot be practically expressed and it may even be that the probability of a random number being theoretically indescribable is about 100%. Depending on what a number is. > Some problems can be avoided if you use bignums. Or that. My momentary existential angst has been assuaged. Thanks bignums.
- mananaysiempre 2y ago> existential angst The best (and most educational) expression of that angst that I know: https://mathwithbaddrawings.com/2016/12/28/why-the-number-line-freaks-me-out/ https://mathwithbaddrawings.com/2016/12/28/why-the-number-li....
- roenxi 2y agoUncomputable! That was the word I wanted. I only remembered constructability but that was something else. Thanks.
- TeMPOraL 2y agoWait. Could we in principle find more ways to express some of those uncomputable numbers, or have we conclusively proven we just can't reach them - can't identify any of them in any way we could express? EDIT: let me guess - there is a proof, and it's probably a flavor of the diagonal argument, right?
- analog31 2y agoYes there's a proof. One flavor is that in any system for expressing numbers using symbols, you can show a correspondence between finite strings of symbols, and whole numbers. So, what works for whole numbers also works for things like proofs and formulas. I think the correspondence may be called "Goedel numbering."
- throw0000111 2y agoThere are two ways to read that question. If hypercomputation is possible, then there might be a way to express some of those uncomputable numbers. They just won't be possible with an ordinary Turing machine. (If description is all you need, then it's already possible to describe some uncomputable numbers like Chaitin's constant. But you can't reliably list its digits on an ordinary computer.) As for the other interpretation, "have we conclusively proven we can't reach them with an ordinary computer", IIRC, the proof that there are infinite uncomputable numbers is as follows: Consider a finitely large program that, when run, outputs the number in question. This program can be encoded as an integer - just read its (binary or source) bytes as a very large base-256 number. Since the set of possible programs is no larger than the set of integers, it's (at most) countably infinite. However, the real numbers are uncountably infinite. Thus a real number is almost never computable.
- jwmoz 2y agoNot a calculator engineer but this seems hideously complex?
- tim-kt 2y agoFor an everyday use calculator? Sure. It's still fun and challenging to create a calculator that can handle "as much" math/arithmetics as possible.
- grandempire 2y agoIt’s really not just for experts though. Even dealing with fractions is going to require more than a naive implementation.
- dgacmu 2y agoMaybe, though in the paper (not the article): > We no longer receive bug reports about inaccurate results, as we occasionally did for the 2014 floating-point-based calculator (with a footnote: This excludes reports from one or two bugs that have now been fixed for many months. Unfortunately, we continue to receive complaints about incorrect results, mostly for two reasons. Users often do not understand the difference between degrees and radians. Second, there is no standard way to parse calculator expressions. 1 + 10% is 0.11. 10% is 0.1. What’s 10% + 10%?) When you have 3 billion users, I can imagine that getting rid of bugs that only affect 0.001% of your userbase is still worthwhile and probably pays for itself in reduced support costs.
- Aardwolf 2y ago> 1 + 10% is 0.11. I know adding % has multiple conventions, but this one seems odd, I'd interpret 1 + 10% as "one plus 10 percent of one" which is 1.1, or as 1 + 10 / 100 which happens to be also 1.1 here The only interpretation that'd make it 0.11 is if it represents 1% + 10%, but then the question of 10% + 10% is answered: 0.2 or 20%. Or maybe there's a typo and it was supposed to say "0.1 + 10%"
- 2y ago
- xixixao 2y agoGreat resource! For my calculator I also wanted to tackle physics, which expands on the number definition with measurement error size. It is suprisingly hard problem. https://recomputer.github.io/ https://recomputer.github.io/
- ConanRus 2y agoyours give 1 on (10^100)+1-(10^100), cool
- Shorel 2y agoAlmost no one has done that calculator app, properly. When I mean properly, I mean a complete calculator, like the TI-89. I am using, in Android, and emulator for the TI-89 calculator. Because no Android app has half the features, and works as well.
- anthk 2y agoMaxima
- orbital-decay 2y agoIt's not even about features. Calculators are mostly useful for napkin math - if I can't afford an error, I'll take some full-fledged math software/package and write a program that will be debuggable, testable, and have version control. But for some reason the authors of calculator apps never optimize them for the number of keypresses, unlike Casio/TI/HP. It's a lost art. Even a simple operator repetition is a completely alien concept for new apps. Even the devs of the apps that are supposed to be snappy, like speedcrunch, seem to completely misunderstand the niche of a calculator, are they not using it themselves? Calculator is neither a CAS nor a REPL. For Android in particular, I've only found two non-emulated calculators worth using for that, HiPER Calc and 10BA by Segitiga.Pro. And I'm not sure I can trust the correctness.
- cgcrob 2y agoProper ones are certainly usable for more than napkin math. I deal with fairly simple definite integrals and linear algebra occasionally. It's easier for me to plug this into a programmable calculator than it is to scratch in the dirt on Maxima or Mathematica most of the time if I just need an answer.
- dgacmu 2y agoAnyone 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.
- netsharc 2y ago> (Also I decided to try writing this thread in the style of a linkedin influencer lol, sorry about that.) I hated reading this buzzfeedy style (or apparently LinkedIn-style?) moron-vomit. I shouldn't complain, just ask my nearest LLM to rewrite this article^W scribbling to a less obnoxious form of writing..
- Kiro 2y agoI liked it.
- Minor49er 2y agoI noticed this too, but I was confused because the calculator article was informative and interesting. It's entirely unlike the inept fluffy slop that gets posted to LinkedIn
- tonyedgecombe 2y agoI think it’s called broetry although perhaps the sentences are a little long for that.
- igravious 2y agoAgreed. And furthermore the content isn't as "wow, who'd a thunk it" as the author seems to think it is. I cannot be unusual in knowing that single and double precision floating point numbers just don't cut it for a lot of arithmetic tasks. Surely this is taught in every comp-sci course? And doesn't nearly everyone know the N ⊆ Z ⊆ Q ⊆ A ⊆ R ⊆ C hierarchy?, well nearly everyone doesn't but surely everyone who either decides to write a calculator app or is tasked with writing one ought to know this? The claim "A calculator app? Anyone could make that." is a patently ridiculous claim to me, anybody who would make such a claim is clearly ignorant of both software development and mathematics. Next article. "A text editor? Anyone could make that."
- raincole 2y agoI really hate when people put cat images and memes in a serious article. Don't get me wrong, the content is good and informative. But I just hate the format. That reminds me when SideFX started putting memes into their official tutorial youtube channel. At least this is just a webpage and we can scroll through them...
- JDEW 2y agoAlso the “highschool poem”-type writing style is quite jarring but forgiven when he acknowledged it at the end of the article. > Also I decided to try writing this thread in the style of a linkedin influencer lol, sorry about that.
- lapcat 2y agoWhile we're already breaking the HN guidelines—"Please don't complain about tangential annoyances—e.g. article or website formats"—let me just say that the scrolljacking on this article is awful.
- ChadNauseam 2y agoI've not intentionally implemented any scrolljacking (I'm using the default obsidian template), but I'm curious what you mean as I also don't see where the scrolljacking would happen. Could you elaborate on the way in which the user experience is awful now, so I can improve it?
- move-on-by 2y agoI enjoyed the article, but it seems Apple has since improved their calculator app slightly. The first example is giving me the correct result today. However, the second example with the “Underflow” result is still occurring.
- NlightNFotis 2y agoI've just tried the first example on iOS 18.3.1 and it absolutely reproduces perfectly for me.
- move-on-by 2y agoOh no- I stand corrected. I tried it again and you are right. I had just woken up when I did my initial test and must have typoed something. I can no longer edit or delete my original comment :(
- yreg 2y agoI remember hearing stories that for a time there was no engineer inside Apple responsible for the iOS Calculator. Now it seems to be revived as there were some updates to it, but those also removed one of my favourite features -> tapping equals button no longer repeats the last operation.
- basicoperation 2y agoThey fortunately fixed the repeating feature in iOS 18.3. Though it does seem a bit ridiculous that something like this is tied to the entire OS version.
- yreg 2y agoOh, nice - thanks! So it was a bug afterall.
- HappyPanacea 2y ago> It's too slow. > 1 is not equal to 1 - e^(-e^1000). But for Richardson and Fitch's algorithm to detect that, it would require more steps than there are atoms in the universe. > They needed something faster. I'm disappointed after this paragraph I expected a better algorithm and instead they decided to give up. Fredrik Johansson in his paper "Calcium: computing in exact real and complex fields" gives a partial algorithm for the problem and writes "Algorithm 2 is inspired by Richardson’s algorithm, but incomplete: it will find logarithmic and exponential relations, but only if the extension tower is flattened (in other words, we must avoid extensions such as e^log(z) or √z^2), and it does not handle all algebraic functions. Much like the Risch algorithm, Richardson’s algorithm has apparently never been implemented fully. We presume that Mathematica and Maple use similar heuristics to ours, but the details are not documented [6], and we do not know to what extent True/False answers are backed up by a rigorous certification in those system".
- gravitronic 2y agoyears ago the daily wtf had a challenge for writing the worst calculator app. my submission maintained calculation state by emitting it's own source code, recompiling and running the new executable.
- LordShredda 2y agoPeople call that a JIT compiler nowadays (?)
- tasty_freeze 2y agoI first learned to program on a Wang 2200 computer with 8KB of RAM, back in 1978. One of the math teachers stayed an hour late most days to allow us nerds to come in an use the two computers. There were more people than computers, so often you'd only get 10 or 15 minutes of time. Anyway, I wrote a program where you could enter an equation and it would draw an ASCII graph of the curve. I didn't know how to parse expressions and even if I had I knew it would be slow. The machine had a cassette tape under computer control for storing and loading programs. What I did was to take the expression typed by the user and convert each one into its tokenized form and write it out to tape. The program would then load that just created overlay which contained something like "1000 DEF FNY(X)=X^2-5" and a FOR loop would sweep X over the designated range, and have "LET Y=FNY(X)" to evaluate the expression for me. As a result, after entering the equation, it would take about five seconds to write out the overlay, rewind a couple blocks, and load the overlay before it would start to plot. But once it started it went pretty fast.
- gravitronic 2y agoThat's a really cool and simple solution to a difficult problem!! I love it!
- smarks 2y agoHey! A fellow Wang 2200 veteran!
- tasty_freeze 2y ago
- 1970-01-01 2y agoI removed telemetry on my Win10 system and now calc.exe crashes on basic calculations. I've reported this but nobody cares because the next step in troubleshooting is to reinstall Windows. So if telemetry fails, calc.exe will silently explode. Therefore no, anyone cannot make it. Won't fix: https://github.com/microsoft/calculator/issues/148 https://github.com/microsoft/calculator/issues/148
- cowsandmilk 2y agoBased on the thread, you can build it from the source code and telemetry won’t be enabled…
- 1970-01-01 2y agoI just use the Win7 binary. Calc.exe is the definition of something that really doesn't need to change.
- noinsight 2y agoHow do you make the Win7 binary run? Last I tried it doesn’t run if you just have the .exe?
- 1970-01-01 2y agohttps://win7games.com/#calc https://win7games.com/#calc
- Aachen 2y agoWindows XP's mspaint.exe stopped working at some point :(. I was also in the team "simple tool worked as I want it to" for as long as that lasted. (I don't use Windows anymore, not for only this reason obviously but still, I don't seem to have these problems anymore where you can't make things work a certain way.)
- trinix912 2y ago> Won't fix: https://github.com/microsoft/calculator/issues/148 https://github.com/microsoft/calculator/issues/148 I don't see how one can expect them to take a report worded this way seriously. Perhaps if they actually reported the crash without the tantrum the team would fix it.
- jll29 2y agoGood read, thanks.
- schneems 2y agoThis is interesting. One of the first ideas I had for an app was a calculator that represented digits like shown in the article but allowed you to write them with variables and toggle between symbolic and actual responses. A use case would be: in a spreadsheet like interface you could verify if the operations produced the final equation you were modeling in order to help validate if the number was correct or not. I had a TI-89 that could do something close and even in 2006 that was not exactly brand new tech. I figured surely some open source library available on the desktop must get me close. I was wildly wrong. I stuck with programming but abandoned the calculator idea. Even nearly 20 years later, such a task doesn’t seem that much easier to me.
- pkaye 2y agoIsn't what you are asking for a CAS?
- AlotOfReading 2y agoThat's a CAS, as mentioned. There are plenty of open source libraries available, but one that specifically implements the algorithms discussed in this article is flintlib. Here's an example from their docs showing exactly what you want: https://flintlib.org/doc/examples_calcium.html#examples-calcium https://flintlib.org/doc/examples_calcium.html#examples-calc...
- schneems 2y agoThanks!
- 11235813213455 2y agorecursive descent parser, normally any decent developer can do that, my version: https://caub.github.io/misc/calculator https://caub.github.io/misc/calculator
- Aardwolf 2y ago"-2 ** 3 SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '*' " That's actually a great error, I have made the mistake of expecting "-2 ** 2" would output 4 instead of -4 before.
- pedrosorio 2y ago^ fyi, this comment reveals you didn't RTFA
- 11235813213455 2y agoCorrect, but my goal was just to get the same result than JS `eval()`except for -n * m because in my opinion this shouln't require parenthesis. It's still a good learn to do this, I don't want to deal with floating points things etc..
- rustybolt 2y agoNice story. An even more powerful way to express numbers is as a continued fraction (https://en.wikipedia.org/wiki/Continued_fraction https://en.wikipedia.org/wiki/Continued_fraction). You can express both real and rational numbers efficiently using a continued fraction representation. As a fun fact, I have a not-that-old math textbook (from a famous number theorist) that says that it is most likely that algorithms for adding/multiplying continued fractions do not exist. Then in 1972 Bill Gosper came along and proved that (in his own words) "Continued fractions are not only perfectly amenable to arithmetic, they are amenable to perfect arithmetic.", see https://perl.plover.com/yak/cftalk/INFO/gosper.txt https://perl.plover.com/yak/cftalk/INFO/gosper.txt. I have been working on a Python library called reals (https://github.com/rubenvannieuwpoort/reals https://github.com/rubenvannieuwpoort/reals). The idea is that you should be able to use it as a drop-in replacement for the Decimal or Fraction type, and it should "just work" (it's very much a work-in-progress, though). It works by using the techniques described by Bill Gosper to manipulate continued fractions. I ran into the problems described on this page, and a lot more. Fun times.
- naniwaduni 2y ago> You can express both real and rational numbers efficiently using a continued fraction representation. No, all finite continued fractions express a rational number (for... obvious reasons), which is honestly kind of a disappointment, since arbitrary sequences of integers can, as a matter of principle, represent arbitrary computable numbers if you want them to. They're powerful than finite positional representations, but fundamentally equivalent to simple fractions. They are occasionally convenient for certain problem structures but, as I'm sure you've already discovered, somewhat less convenient for a wide range of common problems.
- layer8 2y agoThe linked paper by Bill Gosper is about potentially infinite continued fractions with potentially irrational symbolic terms.
- rustybolt 2y ago> No, all finite continued fractions express a rational number Any real number x has an infinite continued fraction representation. By efficient I mean that the information of the continued fraction coefficients is an efficient way to compute rational upper and lower bounds that approximate x well (they are the best rational approximations to x). > They are occasionally convenient for certain problem structures but, as I'm sure you've already discovered, somewhat less convenient for a wide range of common problems. I'm curious what you mean exactly. I've found them to be very convenient for evaluating arithmetic expressions (involving both rational and irrational numbers) to fairly high accuracy. They are not the most efficient solution for this, but their simplicity and not having to do error analysis is far better than any other purely numerical system. > fundamentally equivalent to simple fractions. This feels like it is a bit too reductionist. I can come up with a lot of example, but it's quite hard to find the best rational approximations of a number with just fractions, while it's trivial with continued fractions. Likewise, a number like the golden ratio, e, or any algebraic number has a simple description in terms of continued fractions, while this is certainly not the case for normal fractions. That continued fractions can be easily converted to normal fractions and vice versa, is a strength of continued fractions, not a weakness.
- SloopJon 2y agoI played around with the calculator source code from the Android Open Source Project after a previous submission[1]. I think Google moved it from AOSP to the Google Play Services several years ago, but the old source is still available. It does solve some real problems that I'd love to have available in a library. The discussion on the previous article links to some libraries, but my recollection is that the calculator code is more accessible to an innumerate person like myself. Edit: the previous article under discussion doesn't seem to be available, but it's on archive.org[2]. [1] https://news.ycombinator.com/item?id=24700705 https://news.ycombinator.com/item?id=24700705 [2] https://web.archive.org/web/20250126130328/https://blog.acolyer.org/2020/10/02/toward-an-api-for-the-real-numbers/ https://web.archive.org/web/20250126130328/https://blog.acol...
- yonran 2y ago> I think Google moved it from AOSP to the Google Play Services several years ago, but the old source is still available. For the curious, here is the source of ExactCalculator from the commit before all files were deleted: https://android.googlesource.com/platform/packages/apps/ExactCalculator/+/7265aa3a922a7e7c0389dae4b26cca562aa777a6 https://android.googlesource.com/platform/packages/apps/Exac..., and here is the dependency CR.java https://android.googlesource.com/platform/external/crcalc/+/refs/heads/main https://android.googlesource.com/platform/external/crcalc/+/...
- ksec 2y agoSo did they fix the iOS Calculator bug? On another note. Since Calculator is so complex are there any open source cross platform library that makes it easier to implement?
- perlgeek 2y agoI imagine you could do most or all of this with yacas, which is actually a computer algebra system (GPL).
- troymc 2y agoFrom the linked post: 'A "computer algebra system" would have accomplished a similar goal, but been much slower and much more complicated'
- perlgeek 2y agoWriting a CAS from scratch would've been much more complicated. Reusing an existing one? Maybe not. Yes, it would likely be slower, but is a 1ms vs. 10ms response time in the calculator app really such a big deal? entering a correct calculation / formula on the smartphone likely takes much longer.
- Kiro 2y agoHe was not working on the iOS Calculator.
- mg 2y agoTo make any type of app really good is super hard. I have yet to see a good to-do list tool. I'm not kidding. I tried TickTick, Notion, Workflowy ... everything I tried so far feels cumbersome compared to how I would like to handle my To-Do list. The way you create, edit, browse, drag+drop items is not as all as fluid as I imagine it. So if anyone knows a good To-Do list software (must be web based, so I can use it anywhere without installing something) - let me know!
- solumunus 2y agoI find Trello adequate.
- mg 2y agoOne issue I have with Trello is that it has multiple types of items. And that it is not recursive. When I create an item "Supermarket" and then an item "Bread", I cannot drag and drop the item "Bread" into "Supermarket". But that is how I think. I have a lot of "items" and each item can contain other "items". I don't want any other type of object. Another problem is that I cannot customize the layout. I can't remove every icon from the items in the list. I only want to see the item names, no other info like the icon that shows that there is a description or anything. But Trello seems to not support that.
- erikerikson 2y agoI use Google's Keep but you may need to make your own
- jaredhallen 2y agoI agree that Keep is pretty good. I switched over to Carnet when I setup my nextcloud. It's OK, but not as good as Keep.
- philipwhiuk 2y agoTo-Do List is an infinite product category. They are extremely personal and any unwanted features end up as friction. You'll never find a perfect Todo app because it will have an audience of 1 so wouldn't be made. Other examples of Todo apps: Things, 2Do, Todoist, OmniFocus, Due, Reminders (Apple), Clear, GoodTask, Notes, Google Keep The list is literally neverending,
- based2 2y agohttps://github.com/based2/KB/blob/main/math/aaa.md#calculator https://github.com/based2/KB/blob/main/math/aaa.md#calculato...
- red_admiral 2y agoThere's a point at which you're really building a computer algebra system. Or you can do what the Windows 11 calculator does and not even get 1+2*3 right.
- tasty_freeze 2y agoI'm on windows 11. I just did it and it replied "7". I subtracted 7 to see if there was some epsilon error but it reported "0". What do you experience?
- gsck 2y agoAre you in standard or scientific? Each new operator (Not sure if thats the correct term) is calculated immediately. ie 1+2x3 is worked out as 1+2 (Stored into buffer as 3) x 3 = 9 But scientific does it correctly where it just appends the new expression onto the buffer instead of applying it
- thomaspark 2y agoI solved this by making a calculator that rounds to the nearest 1/16. Tiny app for Americans doing DIY work around the house: https://thomaspark.co/projects/calc-16/ https://thomaspark.co/projects/calc-16/
- adilcanq 2y agolowkey this is why ieee 754 floating point is both a blessing and a curse, like yeah it’s fast n standardized but also introduces unavoidable precision loss, esp w iterative computations where rounding errors stack up in unpredictable ways. ppl act like increasing precision bits solves everything. but u just push the problem further down, still dealing w truncation, cancellation, etc. (and edge cases where numerical stability breaks down.) … and this is why interval arithmetic and arbitrary precision methods exist, so it gives guaranteed bounds on error instead of just hoping fp rounding doesn’t mess things up too bad. but obv those come w their own overhead: interval methods can be overly conservative, which leads to unnecessary precision loss, and arbitrary precision is computationally expensive, scaling non-linearly w operand size. wonder if hybrid approaches could be the move, like symbolic preprocessing to maintain exact forms where possible, then constrained numerical evaluation only when necessary. could optimize tradeoffs dynamically. so we’d keep things efficient while minimizing precision loss in critical operations. esp useful in contexts where precision requirements shift in real time. might even be interesting to explore adaptive precision techniques (where computations start at lower precision but refine iteratively based on error estimates).
- GistNoesis 2y agoThat's just a single number to calculate. The real fun begins when you do geometry. Find a representation of finite memory to represent points, which allows exact addition, multiplication and rotation between them, (with all the nice standard math property like associativity and commutativity). For example your representation should be able to take a 2d point A, aka two coordinates, and rotate it around the origin by an angle theta to obtain the point B. Take the original point and rotate it by pi + theta, then reflect it around the origin to obtain the point C. Now answer the question whether B is coincident with C.
- kccqzy 2y agoJust use Mathematica. ar = Sqrt[ax^2 + ay^2]; atheta = ArcTan[ax, ay]; br = ar; btheta = atheta + theta; cr = ar; ctheta = atheta + Pi + theta + Pi; bx = br Sin[btheta]; by = br Cos[btheta]; cx = cr Sin[ctheta]; cy = cr Cos[ctheta]; In[2]:= bx == cx Out[2]= True In[3]:= by == cy Out[3]= True This seems so elementary that I think open source computer algebra systems can do it.
- GistNoesis 2y agoThe point underlying the problem is about the closure of operations [1] Typically one would like to be able to calculate things without making error, which accumulates. The symbolic representation you suggest use a growing memory to represent the point by all the operations which have been applied to it since the origin. What we would rather do is define a set of operation that are closed for a specific set of points, which allows to accumulate information by doing the computation rather than deferring the computation. One could for example think of using fixed point number to represent the coordinates, and define an extra point at the infinity to handle overflow. And then you have some property that you like and some that you like less. For example minimums distance which can define a point uniquely in continuous R^2, are no longer unique when you constrain yourself to integer grids by using fixed points. Or you could use some rational numbers to store the coordinates like in CGAL (which allows you to know on which sides of the planes you are without z-fighting), but they still require growing memory. You can maybe add some rule to handle the underflow and overflows. Or you can merge close points, but maybe you lose some information. Or you can define the operations on lattices, finite automaton, or do some error correcting codes, dynamic recombining graphs (aka the ruliad). It's an open problem, see https://en.wikipedia.org/wiki/Robust_geometric_computation https://en.wikipedia.org/wiki/Robust_geometric_computation for more. [1] https://en.wikipedia.org/wiki/Closure_(mathematics) https://en.wikipedia.org/wiki/Closure_(mathematics)
- wiz21c 2y agoI use qalculate, it behaves well enough for my needs. https://qalculate.github.io/ https://qalculate.github.io/
- librasteve 2y agoI just tried this in raku App::Crag... crag 'say (10*100) + 1 − (10*100)' #1 Raku uses Rats by default (Rational numbers) unless you ask for floating point.
- mynegation 2y agoAs soon as I read the title, I chuckled, because coming from the computational mathematics background I already knew what it roughly is going to be about. IEEE 754 is like democracy in a sense that it is the worst, except for all the others. Immediately when I saw the example I thought: it is either going to be either a Kahan summation or full-scale computer algebra system. It turned out to be some subset of the latter and I have to admit I have never heard of Recursive Real Arithmetic (I knew of Real Analysis though). If anything that was a great insight about one of my early C++ heroes, and what they did in their professional life outside of the things they are known for. But most importantly it was a reminder how deep seemingly simple things can be.
- titzer 2y agoIEEE 754 is what you get if you started with the idea of sign, exponent, and fraction and made the most efficient hardware implementation of it possible. It's not "beautiful", but it falls out pretty straightforwardly from those starting assumptions, even the seemingly weirder parts like -0, subnormals and all the rounding modes. It was not really democratically designed, but done by numerical computing experts coupled with hardware design experts. Every "simplified" implementation of floating point that has appeared (e.g. auto-FTZ mode in vector units) has eventually been dragged kicking and screaming back to the IEEE standard.
- AlotOfReading 2y agoAnother way to see it is that floating point is the logical extension of fixed point math to log space to deal with numbers across a large orders of magnitude. I don't know if "beautiful" is exactly the right word, but it's an incredibly solid bit of engineering.
- dan-robertson 2y agoI feel like your description comes across as more negative on the design of IEEE-754 floats than you intend. Is there something else you think would have been better? Maybe I’m misreading it. Maybe the hardware focus can be blamed for the large exponents and small mantissas. The reasonable only non-IEEE things that comes to mind for me are: - bfloat16 which just works with the most significant half of a float32. - log8 which is almost all exponent. I guess in both cases they are about getting more out of available memory bandwidth and the main operation is f32 + x * y -> f32 (ie multiply and accumulate into f32 result). Maybe they will be (or already are) incorporated into IEEE standards though
- adamddev1 2y agoThe way this article talks about using "recursive real arithmetic" (RRA) reminds me of an excellent discussion with Conal Elliot on the Type Theory For All podcast. He talked about moving from representing things discretely to representing things continually (and therefore more accurately). For instance, before, people represented fonts as blocks of pixels, (discrete.) They were rough approximations of what the font really was. But then they started to be recognized as lines/vectors (continual), no matter the size, they represented exactly what a font was. Conal gave a beautiful case for how comp sci should be about pursuing truth like that, and not just learning the latest commercial tool. I see the same dogged pursuit of true, accurate representation in this beatiful story. - https://www.typetheoryforall.com/episodes/the-lost-elegance-of-computation https://www.typetheoryforall.com/episodes/the-lost-elegance-... - https://www.typetheoryforall.com/episodes/denotational-design https://www.typetheoryforall.com/episodes/denotational-desig...
- ChadNauseam 2y agoThanks, that's a lovely analogy and I'm excited to listen to that podcast. I think the general idea of converting things from discrete and implementation-motivated representations to higher-level abstract descriptions (bitmaps to vectors, in your example) is great. It's actually something I'm very interested in, since the higher-level representations are usually much easier to do interesting transformations to. (Another example is going from meshes to SDFs for 3D models.) You might get a kick out of the "responsive pixel art" HN post from 2015 which implements this idea in a unique way: https://news.ycombinator.com/item?id=11253649 https://news.ycombinator.com/item?id=11253649
- adamddev1 2y agoThanks, that "responsive pixel art" is very cool!
- t43562 2y agoI doubt that most people using the calc app expect it to handle such situations. It's nice that it does of course but IMO it misses the point that the inputs to a lot of real world calculations are inaccurate to start with. i.e it's more likely that I've made a few mm mistake when measuring the radius of my table than that I'm not using an precise enough version of Pi. The area of the table will have more error because one is squaring the radius, obviously. It would be interesting to have a calculator that let you add in your estimated measurement error (or made a few reasonable guesses about it for you) and told you the error in your result e.g. the standard deviation. I sometimes want to buy stuff at a hardware shop and I think : "how much paint do I need to buy?" I haven't planned so I'm thinking "it's about 4m by 5m...I think?" I try to do a couple of calculations with worst case numbers so I at least get enough paint and save another trip to the shop but not comically too much so that I have a tin of it for the next 5 years. I remember having to estimate error in results that were calculated from measured values for physics 101 and it was a pain.
- grandempire 2y agoThis is a crazy take to me. Most people don’t care that a calculator gives them a correct answer? It’s just an estimator? Why would we not expect it to work when we know how to build ones that do, and people use it as a replacement for math on paper?
- t43562 2y agoEverything in life is estimation. A calculator that tells you the perfect answer in some highly unusual situation probably isn't fixing the most common source of error. e.g I measure an angle and I am not sure about whether it's 45 degrees or 46 then an answer like this is pointless: 0.7071067811865476 cos of 46 (if I've converted properly to radians) is 0.6946583704589973 so my error is about 0.01 and those long lists of digits imply a precision I don't have. I think it would be more useful for most people to tell them how much error there is in their results after guessing or letting them assign the estimated error in their inputs.
- 2y ago
- staplung 2y agoAll the calculators that I just tried for the article's expression give the wrong answer (HP Prime, TI-36X Pro, some casio thing). Even google's own online calculator gives the wrong answer, which is mildly ironic. [https://www.google.com/search?q=1e101%2B1-1e101&oq=1e101%2B1 https://www.google.com/search?q=1e101%2B1-1e101&oq=1e101%2B1] I played around with the macOS calculator and discovered that the dividing line seems to be at 1e33. I.e. 1e33+1-1e33 gives the correct answer of 1 but 1e34+1-1e34 gives 0. Not sure what to make of that.
- Const-me 2y ago> the dividing line seems to be at 1e33.. Not sure what to make of that That’s not too bad. They are probably using hand-rolled FP128 format for their numbers. If they were using hardware-provided FP64 arithmetic, the threshold would have been 2^53 ≈ 9E+15: https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64 https://en.wikipedia.org/wiki/Double-precision_floating-poin...
- qwezxcrty 2y agoTried with the HP Prime and it gave the precise 1 for the test. One need to put it in the CAS mode and use the exact form of 10^100 instead of 1E100. You shall get the right answer if the calculator is instructed to use its very powerful CAS engine.
- Const-me 2y agoDue to backwards compatibility modern PC CPUs have some mathematical constants in hardware, one of them Pi https://www.felixcloutier.com/x86/fld1:fldl2t:fldl2e:fldpi:fldlg2:fldln2:fldz https://www.felixcloutier.com/x86/fld1:fldl2t:fldl2e:fldpi:f... Moreover, that FLDPI instruction delivers 80 bits of precision, i.e. more precise than FP64. That’s pretty much useless in modern world because the whole x87 FPU is deprecated. Modern compilers are generating SSE1 and SSE2 instructions for floating-point arithmetic, instead of x87.
- NooneAtAll3 2y ago> Showing 0.0000000000000 on the screen, when the answer is exactly 0, would be a horrible user experience. > They realized that it's not the end of the world if they show "0.000000..." in a case where the answer is exactly 0 so... devs self-made a requirement, got into trouble (complexity) - removed the requirement, trouble didn't go anywhere just keep saying "it's a win" and you'll be winning, I guess
- nightpool 2y agoNo? They made a goal to show 0.0000 in as few places as possible, and they got as close to it as they could without compromising their other requirements.
- HarHarVeryFunny 2y agoInteresting article, and kudos to Boehm for going the extra mile(s), but it seems like overkill to me. I wouldn't expect, or use, a calculator for any calculation requiring more accuracy than the number of digits it can display. I'm OK with with iPhone's 10^100 + 1 = 1e100. If I really needed something better, I'd try Wolfram Alpha.
- kccqzy 2y agoThe thing about this calculator app is that it can display any number of digits just by scrolling the display field. The UX is "any number of digits the user wants" not some predetermined fixed number of digits.
- IsaacL 2y agoI commented about this on X. As a developer, "infinite scroll to get more digits" sounds really cool. It sounds conceptually similar to lazily-evaluated sequences in languages like Clojure and Haskell (where you can have a 'virtually-infinite' list or array -- basically a function -- and can access arbitrarily large indices). As a user, it sounds like an annoying interface. On the rare case I want to compute e^(-10000), I do not want to scroll for 3 minutes through screens filled with 0s to find the significant digits. Furthermore, it's not very usable. A key question in this scenario would be: how many zeroes were there? It's basically impossible to tell with this UI. A better approach is simply to switch to scientific notation for very large or very small numbers, and leave decimal expansion as an extra option for users who need it. (Roughly similar to what Wolfram Alpha gives you for certain expressions.)
- kevinpacheco 2y agoThe NYC subway fare is $2.90. I was using PCalc on iOS to step through remaining MetroCard values per swipe and discovered that AC, 8.7, m+, 2.9, m-, m-, m- evaluates to -8.881784197E-16 instead of zero. This doesn't happen when using Apple's calculator. I wrote to the developer and he replied, "Apple has now got their own private maths library which isn't available to developers, which they're using in their own calculator. What I need to do is replace the Apple libraries with something else - that's on my list!"
- 6SixTy 2y agoSounds like he's just using stock math functions. Both Javascript and Python act the same way when you save the result immediately after subtracting two numbers multiple times, rather than just 8.7 - (2.9*3).
- MatthiasWandel 2y agoI wrote the calculator for the original blackberry. Floating point won't do. I implemented decimal based floating point functions to avoid these rounding problems. This sounds harder than it was, basically, the "exponent" part wasn't how many bits to shift, but what power of two to divide by, so that 0.1, 0.001 etc can be represented exactly. Not sure if I had two or three digits of precision beyond whats on the display. 1 digit is pretty standard for 5 function calculators, scientific ones typically have two. It was only a 5 function calculator, so not that hard, plus there was no floating point library by default so doing any floating point really ballooned the size of an app with the floating point library.
- kragen 2y agoHoly shit, I thought you just made mindblowing mechanical devices. I can see why you wouldn't necessarily just want to use it, but I thought the RIM pager had a JVM with floating point? I mostly just used mine for email.
- MatthiasWandel 2y agoThe JVM based devices came years later. This was around 1998, with the 386 based blackbery pager that could only do emails over Mobitex, no phone calls. It even looked like a pager. At the time, phones were not so dominant, data switched over mobile only existed on paper, and two-way paging looked like it had a future. So we totally killed the crude 2-way paging networks that were out there. And RIM successfully later made the transition to phone networks. Wasn't till iPhone and android that RIM ran into trouble.
- donatj 2y agoWas given the task to build a simple calculator app as a project for a Java class I took in college. No parens or anything like that, nothing nearly so fancy. Classic desk calculator where you set the infix operation to apply to the previous value, followed by the second value of the operation. It was frankly an unexpected challenge. There's a lot more to it than meets the eye. I only got as far as rational numbers though. PI accurate to the 8 digit display was good enough for me. Honestly though, I think it was a great exercise for students, showing how seemingly simple tasks can actually be more complex than they seem. I'm still here thinking about it some twenty years later.
- joelburget 2y agoI wrote an OCaml implementation of this paper a few years ago, which I've now extracted into its own [repo](https://github.com/joelburget/constructive-reals/blob/main/Constructive_reals.ml https://github.com/joelburget/constructive-reals/blob/main/C...) The link in the paper to their Java implementation is now broken: does anyone have a current link?
- pclmulqdq 2y agoAt some point, when I get a spare 5 years (and/or if people start paying for software again), I will start to work on a calculator application. Number system wrangling is quite fun and challenging, and I am hoping to incorporate units as a first-class citizen.
- ShaggyHotDog 2y agoSaw the thread on Twitter. Kudos to the author for going in so much detail!
- chaboud 2y agoThere’s a pleasantly elegant “hey, we’ve solved the practical functional complement to this category of problems over here, so let’s just split the general actual user problem structurally” vibe to this journey. It often pays off to revisit what the actual “why” is behind the work that you’re doing, and this story is a delightful example. I wrote an arbitrary precision arithmetic C++ library back in the 90’s. We used it to compute key pairs for our then new elliptic-curve based software authentication/authorization system. I think the full cracks of the software were available in less than two weeks, but it was definitely a fun aside and waaaay too strong of a solution to a specific problem. I was young and stupid… now I’m old and stupid, so I’d just find an existing tool chain to solve the problem.
- mgaunard 2y agoCould have just used an off-the-shelf CAS.
- grandempire 2y agoThe point of the article is to teach you how calculators work. Not find a piece of software to unblock you. You may well find yourself in the field of computing having to compute something!
- mgaunard 2y agoThe point of the article is to show building a calculator requires a CAS, which should have been obvious to anyone with a basic understanding of how a calculator works. The premise of the article is itself somewhat bogus, but I suppose there are programmers today who never had to work with a graphing calculator. While RRA is an interesting approach, ultimately it wasn't sufficient. Re-using an off-the-shelf CAS would have been the more practical solution, avoiding all the extra R&D on a novel number representation that wasn't quite sufficient to do the job.
- jedberg 2y agoI thought this was going to be about how Apple completely destroyed the calculator on iOS with the latest update. Now it does the running ticker tape thing, which means you can't use the AC button to quickly start over, because there is no AC button anymore! I know it's supposed to be easier/better for the user, but they didn't even give me a way to go back to the old behavior.
- daitangio 2y agoAs far as I know, windows calculator have a similar approach. It use rational, and switch to Taylor expansion to try to avoid cancellation errors. Microsoft open sourced it some times ago on GitHub
- shutupnerd0000 2y agoWhy does the author insist on using a dick bar? With the "contact me" portion, it takes up 30% of my screen on an iPhone SE.
- Aachen 2y agoA what? I'm also reading this on an sPhone but don't remember seeing anything that looked like, well... what you said
- ChadNauseam 2y agoThere should have been an "x" on the right of the "contact me" portion that you could click to make it go away. Sounds like it didn't show up for you, so sorry about that. Unfortunately I don't have an iPhone SE to test against and the "x" does seem to show up on the iPhone SE screen-size simulator in Chrome. This means I don't know how to reproduce the issue and probably won't be able to resolve it without removing the "contact me" page entirely, which I'm not willing to do right now.
- Synaesthesia 2y agoReally interesting article. I noticed that my Android calculator app could display irrational numbers like PI to an impressive amount of digits, if I hold it sideways.
- kccqzy 2y agoYou can also scroll it to make it display more digits.
- Synaesthesia 2y agoThat is so cool
- gweinberg 2y agoAt the risk of coming across as being a spoilsport, I think when someone says "anyone can write a calculator app", they just mean an app that simulates a pocket calculator (which is indeed pretty easy) as opposed to one which always gives precisely the right answer (which is indeed impossible). Also, you can avoid the most embarrassing errors just by rearranging the terms to do cancellation where possible, e.g. sqrt(2) * 3 * sqrt(2) is absolutely precisely 6, not 6 within some degree of approximation.
- grandempire 2y agoPocket calculators are not using 32 bit floating point math.
- zinekeller 2y agoIn fact, even cheap no-name calculators are using BCD (binary-coded decimal) instead of "normal" representation of numbers.
- lmm 2y ago> as opposed to one which always gives precisely the right answer (which is indeed impossible) Per the article, it's completely possible. Frankly I'd say they found the obvious solution, the one that any decent programmer would find for that problem.
- macintux 2y ago> Frankly I'd say they found the obvious solution, the one that any decent programmer would find for that problem. That statement seems to belittle the amount of effort and thought described in the article. And wildly contradicts my experience.
- lmm 2y agoIt... really doesn't seem like a lot of effort and thought. I feel like anyone who's implemented a command algebra for anything is already halfway there.
- nabaraz 2y agoRe: (10^100)+1-(10^100) i) Answer is 0 if you cancel out two expression (10^100) ii) Answer is 1 if you compute 10^100 and then add 1 which is insignificant. How do you even cater for these scenarios? This needs more than arithmetic.
- Sharlin 2y agoUh, what do you mean? The answer is very obviously 1 no matter what.
- fsckboy 2y ago>The answer is very obviously 1 no matter what no, because only in our imaginations and in no place in the universe can we ignore significance of measurements. If we are sending a spaceship to an interstellar object 1 light year away from earth, and the spaceship is currently 25 miles from earth (on the way), you are insisting that you know more about the distance from earth to the object than you do if you think that that distance from the spaceship to the galaxy is 587862819274.1 miles
- kccqzy 2y agoYou are discussing physics. Everyone else in this thread is discussing mathematics. Sorry but you are the one who's off topic.
- fsckboy 2y agowhy would a computer make the mistake that EVERYONE HERE CAN'T GROK? for the reasons in my comment, and in, according to you, nobody else's. also, the commment I was replying to said "1 no matter what" and I was pointing out where it would matter what.
- nabaraz 2y agoObviously it is 1. But try it on iOS calculator, answer is 0. Reason is when computing large numbers e.g. 100000........n + 1 - 100000........n, addition of 1 is pretty in-significant.
- cubefox 2y agoSlightly disappointing: The calculator embedded in Google's search page also gives the wrong answer (0) for (10^100) + 1 − (10^100). So apparently they don't use the insights they gained from their Android calculator.
- ajnin 2y agoInteresting article but that feels like wasted effort for what is probably the most bare-bones calculator app out there. The Android calc app has the 4 operations, sin cos tan ^ ln log √ ! And that's it. I think most people serious about calculator usage either have a physical one or use another more featureful app and the others don't need such precision.
- CydeWeys 2y agoIt's not wasted effort at all, as this app comes installed by default for over a billion users. Only a tiny fraction will ever install another calculator app, so the default one better work entirely correctly. When you have that many users it's hard to waste effort on making the product better.
- CydeWeys 2y ago> Obviously we'll want a symbolic representation for the real number 1 Sorry, why is this obvious? A basic int type can store the value of 1, let alone the more complicated Rational (BigNum/BigNum) type they have. I can absolutely see why you want symbolic representations for pi, e, i, trig functions, etc., but why one?!
- earthicus 2y agoI think the issue was that they are representing a real as a product of a rational and that more complicated type, so without a symbolic representation for 1, when representing and rational, they would have to multiply it by a RRA representation of 1 which brings in all the decision problem issues.
- ChadNauseam 2y agoYep, this is exactly it!
- ChadNauseam 2y agoSorry for being unclear about this. A number is being expressed as a rational times a real. In the case where the rational is exactly the number we want, we want to be able to set the real to 1, so the multiplication has no effect
- CydeWeys 2y agoAhhh OK so it's essentially the null or identity value, saying "you don't need this component for an exact representation". That makes sense, thanks.
- ComputerGuru 2y agoBecause they express numbers as rational times a real, so the real in all those cases would be one. When it’s one, you do rational math as normal without involving reals.
- stackedinserter 2y agoYes, anyone can make a calculator. I don't care if it gives me "Underflow" for bs like e^-1000, just give me a text field that will be calculated into result that's represented in the way I want (sci notation, hex, binary, ascii etc whatever). All standard calculators are imitations of a desktop calculator, It's insane that we're still dragging this UI into desktop. Why don't we use rotary dial on mobile phones then? It's great that at least OSX have cmd+space where I can type an expression and get a quick result. And yes, I did develop my own calculator, and happily used it for many years. TLDR: the real problem of calculators is their UI, not arithmetic core.
- deleted 2y ago[deleted]
- purplezooey 2y ago"Over the past year or so, I've reluctantly come to the conclusion I need to leave Elm and migrate to some other MUA like PINE or mutt..."
- semolinapudding 2y agoThat's pretty cool, but the downsides of switching to RRA are not only about user experience. When the result is 0.0000000..., the calculator cannot decide whether it's fine to compute the inverse of that number. For instance, 1/(atan(1/5)-atan(1/239)-pi/4) outputs "Can't calculate". Well alright, this is a division by zero. But then you can try 1/(atan(1/5)-atan(1/239)-pi/4+10^(-100000)), and the output is still "Can't calculate" even though it should really be 10^100000.
- kccqzy 2y agoYou missed a 4. You are trying to say 1/(4atan(1/5)-atan(1/239)-pi/4) is a division by zero. On the other hand 1/(atan(1/5)-atan(1/239)-pi/4) is just -1.68866...
- semolinapudding 2y agoGood catch, thank you.
- darkhorse222 2y agoI really do think we should just use the symbolic systems of math rather than trying to bring natural world numbers into a digital number space. It's this mapping that inherently leads to compensating strategies. I guess this is called an algebraic system like the author mentioned. But I view math as more of a string manipulation function with position-dependent mapping behavior per character and dependency graphs, combined with several special functions that form the universal constants. Just because data is stored in digitization as 1 and O, don't forget it's more like charged and not charged. Computers are not numeric systems, they are binary systems. Not the same thing.
- stevage 2y agoI really wonder what the business case for spending so much effort on such precision was. Who are the users who need such accuracy but are using android calculator?
- 6510 2y agowhile phones are mostly a circus people do try to use them for serious things. For a program you make the calculations as accurate as the application requires. If you don't know what a tool will be used for you never really get to feel satisfied.
- kccqzy 2y agoStudents learning about real numbers. Yes seriously. Unlike software engineers who have already studied IEEE754 numbers, you can't expect a middle school student to know concepts like catastrophic cancellation. But a middle school student wants to poke around with trigonometric functions and pi to study their properties, but a true computer algebra system might not be available to them. They might not understand that a random calculator app doesn't behave correctly because it's not using the same kind of numbers discussed in their math class.
- deleted 2y ago[deleted]
- chacha21 2y agoI share a lot of thoughts with that, and built my own calculator, too A calculator that gives right instead of wrong answers https://chachatelier.fr/chalk/chalk-home.php https://chachatelier.fr/chalk/chalk-home.php I tried to explain what was going on https://chachatelier.fr/chalk/article/chalk.html https://chachatelier.fr/chalk/article/chalk.html, but it's not a very popular topic :-)
- sxldier 2y agoLooks really well done, nice!
- elif 2y agoNah yea you can over engineer anything. In the year he did this he easily could have just done some minor interface tweaks to a ruby repl which includes the BigDecimal library. In fact I bet this post to an AI could result in such a numerically accurate calculator app. maybe as a Sinatra single file ruby web app designed to format to phone resolutions natively.
- MiddleEndian 2y agolol I ran into this when making a calculator program because Google's calculator didn't do certain operations (such as adding clock time results like 1:23+1:54) and also because Google occasionally accuses me of being a bot when I search for too many equations. Maybe I'll get back to the project and finish it this year.
- ChuckMcM 2y agoDoes anyone know if this was the system used by higher end TI calculators like the TI-92? It had a 'rational' mode for exact answers and I suspect that it used RRA for that.
- bruckie 2y agoThe TI-92 and similar have a full-on computer algebra system that they use when they're in exact mode [1]. It does symbolic manipulation. This is different from what the post (and linked paper) discuss, where the result will degrade to recursive real arithmetic, which is correct but only to a bounded level of precision. A CAS will always give a fully-exact (although sometimes very unwieldy) answer. [1] See page 87 here: https://sites.science.oregonstate.edu/math/home/programs/undergrad/TI_Manuals/ti92Guidebook.pdf https://sites.science.oregonstate.edu/math/home/programs/und...
- laidoffamazon 2y agoThis is really cool, but it does show how Google works. They’ll pay this guy ~$3million a year (assuming stock appreciation) to do this but almost no end user will appreciate it in the calculator app itself.
- andrelaszlo 2y agoπ+1−π = 1.0000000000000 But π−π = 0 I think I understand why, from the article, but wouldn't it be "easy" (probably not, but curious about why) to simplify the first expression to (1-1)π + 1 then 0π + 1 and finally just 1 before calculating a result?
- kllrnohj 2y agothat would require an algebraic solver which is definitely possible but more complex than really warranted for a "basic" calculator
- LordGrignard 2y agoThis article was really well written. Usually in such articles i understand about 50%, maybe if I'm lucky 70% but this one I've understood nearly everything. It's not much of a smartness thing but an absolute refusal on my part to learn the jargon of programming as well as my severe lack of knowledge of all the big words that are thrown around lol. But really simply written love it
- nagonago 2y agoUnrelated to the article, but this reminds me of being an intrepid but naive 12-year-old trying to learn programming. I had already taught myself a bit using books, including following a tutorial to make a simple calculator complete with a GUI in C++. However I wasn't sure how to improve further without help, so my mom found me an IT school. The sales lady gave us a hard sell on their "complete package" which had basic C programming but also included a bunch of unnecessary topics like Microsoft Excel, etc. When I tried to ask if I could skip all that and just skip to more advanced programming topics, she was adamant that this wasn't an option; she downplayed my achievements trying to say I basically knew nothing and needed to start from the beginning. Most of all, I recall her saying something like "So what, you made a calculator? That's so simple, anybody could make that!" However in the end I was naive, she was good at sales, and I was desperate for knowledge, so we signed up. However sure enough the curriculum was mostly focused on learning basic Microsoft Office products, and the programming sections barely scraped the surface of computer science; in retrospect, I doubt there was anybody there qualified to teach it at all. The only real lesson I learned was not to trust salespeople. Thank god it's a lot easier for kids to just teach themselves programming these days online.
- throwaway2037 2y agoNice story. Thank you share. For years, I struggled with the idea of "message passing" for GUIs. Later, I learned it was nothing more than the window procedure (WNDPROC) in the Win32 API. <sad face> > However I wasn't sure how to improve further without help, so my mom found me an IT school. This sounds interesting. What is an "IT school"? (What country? They didn't have these in mine.)
- sokz 2y agoProbably institutes teaching IT stuff. They used to be popular (still?) in my country (India) in the past. That said, there are plenty of places which train in reasonable breadth in programming, embedded etc. now (think less intense bootcamps).
- nagonago 2y agoThis was in Bangkok, Thailand, although the school itself was run by Indians. They had IT courses for both kids and adults. Fortunately I think these days there are a lot more options for kids to learn programming, but back then the options were pretty limited.
- phendrenad2 2y agoIf you accept that Pi and Sqrt(2) will be represented as a terminating series of digits (say, 30), then 99% of the problems stated go away. My HP calculator doesn't represent the square root of 2 as a magic number, it's 1.414213562.
- tiltowait 2y agoSome quick research yields a couple of open source CAS, such as OpenAxiom, which uses the Modified BSD license. Granted that Google has strong "NIH" tendencies, but I'm curious why something like this wasn't adapted instead of paying several engineers some undisclosed amount of time to develop a calculation system. The article mentions that a CAS is an order of magnitude (or more!) more complex than the bifurcated rational + RRA approach, as well as slower, but: the complexity would be solved by adapting an open source solution, and the computation speed wouldn't seem to matter on a device like an Android smartphone. My HP Prime in CAS mode runs at 400MHz and solves every problem the Android calculator solves with no perceptible delay. Is it a matter of NIH? A legal issue with the 3-clause BSD license I don't understand? Reducing binary size? The available CAS weren't up to snuff for one reason or another? Some other technical issue? Or, if not that, why not use binary-coded decimal? These are just questions, not criticisms. I have very very little experience in the problem domain and am curious about the answers :)
- Mudasir_Fayaz 2y agonice story, building calculator at that time was a tough task today building calculator is just a prompt away inspiring
- wodenokoto 2y agoHasn't this been solved in cheap pocket calculators for decades before this? HP scientific calculators goes back to the 60's and can presumably add 0.6 to 3 without adding small values to the 20th significant digit.
- deleted 2y ago[deleted]
- hoseja 2y agoNo it is easy, you just throw up a math error whenever a smartass tries something like this. Like calculators do.
- enricojr 2y agoCould this be the reason why iPads haven't had a calculator app until recently? Because it's such a difficult problem to solve that it required elite coders and Masters/PhD level knowledge to even make an attempt? (Apple Finally Plans To Release a Calculator App for iPad Later This Year)[https://www.macrumors.com/2024/04/23/calculator-app-for-ipad-rumor/ https://www.macrumors.com/2024/04/23/calculator-app-for-ipad...]
- wartijn_ 2y agoI haven’t really used the iPad’s calculator app, but it looks exactly like a larger version of the iPhone app. So I don’t think there are any technical reasons why it took so long for the iPad to get that app.
- charlieok 2y agoThe bar for "the greatest calculator app development story ever told" it should be noted, is quite high :) https://www.pacifict.com/story/
- scotty79 2y agoOff topic, but I believe naming this specific kind of numbers "real" is a misnomer. Nothing in reality is expression of a real number. Real numbers pop up only when we abstract reality into mathematical models. In Polish language rational numbers are called something more like "measurable" numbers and in my opinion that's the last kind of numbers that is expressed in reality in any way. Those should be called "real" and real should be called something like "abstract" or "limiting" because they pop-up first as limits of some process working on rational numbers for infinite number of steps.
- veltas 2y agoAnd yet Android's calculator is quite bad. Despite being able to correctly calculate stuff that 99.99% of the population don't care about, it lacks many scientific operations that a good chunk of accountants, engineers and coders would make use of regularly. This is a classic situation of engineers solving the fun/challenging problems before the customer's actual problems.
- brettermeier 2y agoWhat exactly is missing? https://imgur.com/a/q0yevdW https://imgur.com/a/q0yevdW
- kstrauser 2y agoGiven the function to compute pi: while (Math.abs(term) > tolerance) { term = ...; sum += term; } return sum * 4; Wouldn’t that return a value where the error of the result is 4x the requested tolerance?
- oldgradstudent 2y ago> This means a calculator built on floating point numbers is like a house built on sand. I've taken multiple numerical analysis courses, including at the graduate level. The only thing I've learnt was: be afraid, very afraid.
- ikanreed 2y agoI use python repl as my primary calculator on my computer. 1. I don't have problems like the IOS problem documented here. This requires me to know the difference between an int and a float, but pythons ints have unbounded precision(except if you overflow your entire memory), so that kind of precision loss isn't a big deal. 2. History is a lot better. Being able to scroll back seems like a thing calculators ought to offer you, but they don't. 3. In the 1-in-a-hundred times I need to repeat operations on the calculator, hey, we've already got loops, this is python 4. Every math feature in the windows default calculator is available in the math library. 5. As bad as python's performance reputation is, it's not at all going to be noticeable for simple math.
- genewitch 2y agoI was always a little envious of the people that could use bc because they knew how. I know python and its installed on linuxes by default, so now I am no longer envious.
- kingkulk 2y agocool story. All programming students should be made to create a calculator in school and have them truly understand the issue at hand.
- insane_dreamer 2y agoHow does an "old school" physical calculator handle the floating point precision problem?
- mcrouther 2y agoHmmm, solved a lot of these problems as well when building my own calculator: https://github.com/crouther/SciCalc https://github.com/crouther/SciCalc Seems like Apple got lazy with their calculator didn't even realize they had so many flaws... Math Notes is pretty cool though.
- cibyr 2y agoPerhaps amusingly, the implementation referenced in Boehm's paper is a still-unmerged Android platform CL adding tests using this approach: https://android-review.googlesource.com/c/platform/art/+/1012109 https://android-review.googlesource.com/c/platform/art/+/101...