4

As most know, you can type mathematical expressions into Spotlight and it will show the result, which you can copy with Cmd-C to paste into other applications. It's mostly intuitive, especially to programmers who are used to notations like ^ and ** for exponentation, but not everything is obvious.

For instance, in a comment to this answer someone pointed out that the expression 1 & -1 produces the unexpected result 0; if -1 is interpreted as its twos-complement representation, that would be 11111..., and bitwise AND with 1 should produce 1, not 0. Some languages like C simply don't specify the result of bitwise operations on negative numbers.

Is there any public documentation of all the operators and functions supported by this calculator, and the way it interprets the operands? I've been trying to find it with google, but the best I could find is a brief mention that you can enter mathematical expressions here; the examples it gives are trivial (one multiplication and one division), and there's no link to more detailed documentation.

7
  • Spotlight calculation is driven by the Calculator app. See: support.apple.com/guide/calculator/welcome/mac
    – Allan
    Commented Jul 7, 2023 at 0:20
  • @Allan So the bitwise operations come from the Programmer mode, although the documentation doesn't say how it deals with negatives. It has 1's and 2's buttons to view the number in these representation, but it doesn't even let me type negatives.
    – Barmar
    Commented Jul 7, 2023 at 0:30
  • I can’t speak to what Apple documents or what functionality they gave their UI.
    – Allan
    Commented Jul 7, 2023 at 0:35
  • @Allan That's why I'm trying to find the documentation! That manual doesn't go into detail, either.
    – Barmar
    Commented Jul 7, 2023 at 0:37
  • That’s why I pointed you to Calc because there’s no Spotlight documentation for this (that I could find; searched for this previously)
    – Allan
    Commented Jul 7, 2023 at 0:43

1 Answer 1

4

Not sure if there is an Apple document on this at all but here are some of the mathematical functions and symbols you can use in formulas while making calculations with Spotlight of macOS Ventura (13.4.1) with examples and the results returned:

Basic: 1 + 1 = 2, 1 - 1 = 0, 2 * 3 = 6, 6 / 2 = 3
Precendence: 2 + 3 * 5 = 17
Parentheses: (1 + 1) / 2 = 2
Multiplication (Implied): 2(8+1) = 18
Absolute Value: abs(-1.1) = fabs(-1.1) = 1.1
Percentage: 25% = 0.25, 60 * 25% = 15
Include unit in formula: 5 miles * 4 = 20 miles
Include a unit conversion in formula: 5 miles * 4 in km = 32.19 kilometers
Use a rate with units in a formula: 20 mph * 5 hours = 100 miles
Modulus (Remainder): 5 % 2 = 1
Base 10 and Natural Logarithms: log(10) = 1, ln(e) = 1,
Exponentiation: 2^3 = 2 ** 3 = 8
Exponentiation (Natural Base): e^2 = e ** 2 = exp(2) = 7,3890560989
Square and Cube Roots: sqrt(4) = 2, cbrt(27) = 3
Factorial: 3! = 6
Trigonometric (Radian): sin(pi/2) = 1, cos(pi) = -1, tan(pi/4) = 1
Trigonometric (Degree): sind(90) = 1, cosd(180) = -1, tand(45) = 1
Trigonometric (Degree): sin(90deg) = 1, cos(180deg) = -1, tan(45deg) = 1
Inverse Trigonometric (Radian): arcsin(1) = 1,57 radians, arccos(-1) = 3,14 radians, arctan(1) = 0,79 radians
Inverse Trigonometric (Degree): arcsind(1) = 90 degrees, arccosd(-1) = 180 degrees, tand(1) = 45 degrees
Hyperbolic: sinh(1) = 1.1752011936, cosh(0) = 1, tanh(0) = 0
Inverse Hyperpolic: arcsinh(1) = 0.881373587; arccosh(1) = 0, arctanh(0.5) = 0.5493061443
Rounding: ceil(1.2) = 2, floor(1.2) = 1, round(1.6) = 2
Bitwise Operators: 3 & 5 = 3 and 5 = 1, 3 | 5 = 3 or 5 = 7, 3 xor 5 = 6
Error and Complementary Error Functions: erf(1) = 0.8427007929, erfc(1) = 0.1572992071

One can combine any of the above symbols or operators, using parentheses for correct prioritization whenever necessary, as shown in the example below:

ln(e **  (4 / sind(90))) = 4

Though the constants pi and e are allowed, variables are not.

To get a result into clipboard, just press Command ⌘+C once the result appears. A calculation result is not shown when the formula is not proper or the outcome is undefined.

Credits:

  1. "Spotlight calculator can do more than simple arithmetic" by Eren Jeager of Reddit, 2013
  2. "Advanced Calculations With Spotlight" by MacMost, 2016
  3. "Advanced Math Calculations Using Spotlight" by MacMost, 2023
3
  • What about bitwise operators with negative operands? That's the thing that prompted the question in the first place.
    – Barmar
    Commented Jul 8, 2023 at 15:17
  • @Barmar The bitwise operators in Spotlight don't seem to work properly with negative numbers. Perhaps it would be best to report this to Apple.
    – Alper
    Commented Jul 8, 2023 at 15:31
  • I'm guessing the answer would be "We follow C's rules, and it only specifies bitwise operations on unsigned types."
    – Barmar
    Commented Jul 8, 2023 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .