subject: The correctly incorrect Spotlight calculator [print this page] The correctly incorrect Spotlight calculator
The Spotlight menu in OS X is an exceptionally useful feature for quickly finding documents by either file name or by content, but in addition it can be used as a launcher for applications and a way to quickly find Web pages you recently visited or items in your e-mail accounts, and in Leopard and Snow Leopard can be used to perform simple calculations.
While for the most part the calculations work, sometimes there are odd behaviors that can give strange results.For instance, if you take a number and divide it by a second number, then multiply the result by the second number, you should end up with the same number you started with:
55 / 3 * 3 = 55
Any mathematician would agree the following function also yields the same results and is in principle the same calculation:
55 * (3 / 3) = 55
If you run both of these in the OS X Calculator application you will get "55" as a result, which makes sense; however, only the second one will give you "55" as the answer when you run them in the Spotlight menu. While the second one will be calculated properly, the first equation will give you "54.999999999" as the answer, which for most purposes is the same as 55, but is not in fact the same number.
The reason for this is a simple oversight in the programming when managing infinite decimal places in a number. When divided by three, the number of decimal points in the result goes to infinity, and every computer will have to round off the digits at some point. Both the Calculator and Spotlight calculate more decimal points than they display onscreen, and both have a point at which they round the number of decimal points up or down; however, Spotlight rounds off numbers to what it displays onscreen after each part of the calculation, which makes it so the number of decimal points required for rounding is not met when the final answeris displayed.