Root calculator

Any root of any number, including the ones most calculators will not give you. The cube root of −8 is −2, because −2 × −2 × −2 is −8 — and almost every calculator on the web returns an error for it. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.

Why your calculator says error

Almost every root calculator computes x1/n, because that is the identity everyone learns. In JavaScript that is Math.pow(x, 1/n), and for a negative x it returns NaN — not a number — whatever n is.

Math.pow(−8, 1/3)NaN
The cube root of −8−2, since −2 × −2 × −2 = −8

The refusal is not mathematics, it is the function. Raising to a fractional power is defined on the complex plane, and pow returns the principal branch — which for a negative base is complex, so a real-valued function gives up. The real answer exists and is easy: take the sign off, root the size, put the sign back.

Odd roots only. There is no real number you can multiply by itself an even number of times to get a negative, because an even number of negative factors is positive. This page says that rather than returning NaN, and says the complex answer exists.

And here is why nobody notices. The cube root of positive 8 is 2 under both methods. Every quick test anyone runs on a root calculator uses a positive number, and the fault is invisible until somebody roots a negative one.

Where to go next