Neatnik

Notes

Apple’s calculator apps considered harmful

Back when iOS debuted, in the era before the App Store when the only things you could run on your grotesquely expensive slab of aluminum and glass were the official apps provided by Apple, I did what pretty much everyone else did: I opened every app and messed around with every single feature. One of those apps was Calculator, and one of the dumb things I did with it was try to divide a number by zero.

I knew it wouldn’t work, because everyone knows that you can’t divide by zero, but I guess I was curious about what the app would do. I didn’t know what to expect, but I definitely didn’t expect what I saw on the screen: NaN. Not a Number. I looked at my phone the way a confused puppy looks at something it can’t make sense of, head slightly tilted. Not a Number?

Let me be clear: I suck at math, and nearly failed it during my senior year of high school. At university, I put off taking any math courses until it was absolutely necessary, and then I dropped out of school entirely. I really don’t like math. But I do value accuracy, and NaN is not an accurate response to an attempted division-by-zero operation.

The “NaN” response was codified in IEEE 754 (“Standard for Floating-Point Arithmetic”) in 1985. It’s a valid response to some attempts at math stuff, like trying to calculate the square root of a negative number or dividing zero by itself. But if you take any number other than zero and try to divide it by zero, the result is not NaN, because there can be no result. The operation is impossible to perform because it is undefined in mathematics. So when dividing a number by zero, the correct response would be to throw an error, or if you want to be fancy about it, you could remind the calculator’s operator that the operation is undefined.

Anyway, after seeing the NaN response and realizing that it was wrong, I did what any Apple nerd would do: I filed a Radar.

Apple eventually fixed the output, and the iOS Calculator app switched to displaying “Error” when trying to divide a number by zero. Nice.

But in the broader Apple Calculator app landscape, serious problems still remain. For instance, dividing zero by itself is not undefined, but (as pointed out above) should return NaN. On iOS, zero divided by zero throws the same error as any number divided by zero. This is wrong! On the macOS Calculator app, zero divided by zero is correctly met with a “Not a number” response (bonus point for spelling it out in the macOS app), but any other number divided by zero in the same app also yields the same “Not a number” response. Which should be an error. On iOS, calculating the square root of a negative number throws an error, when it should be NaN. The macOS app correctly responds with NaN, but it’s pretty clear that’s just because it will always respond with NaN when it doesn’t have a numeric result, just as the iOS app will always respond with Error in the same circumstances.

So much of this is baffling: Apple knows the distinction between NaN and Error, so why can’t they apply the correct responses in each scenario? Why are these two seemingly identical Calculator apps on iOS and macOS running entirely different code? Why can’t we count on the most primitive technical operations on some of the most sophisticated modern equipment to offer reliable, valid responses? Where is the quality control?

Anyway, I don’t actually care about any of this; I just needed a topic for a blog post to test out Robb Knight’s awesome new EchoFeed service. And I’ve also always wanted an excuse to use a “considered harmful” title, so I figured I’d feed two birds with one scone.


The Unofficial weblog.lol Webring · Random Site · Previous Site · Next Site

Recent posts