[x]Blackmoor Vituperative

Tuesday, 2009-08-04

OpenOffice Calc – odd roots of negative numbers

Filed under: Software — bblackmoor @ 17:45

We all learned in grade school that the odd root of a negative number is also negative. The cube root of -8 is -2, for example.

Mathematicians will tell you that -8 has two more roots, but these are not “real” numbers, and unless you are a mathematician, you will never need to know what they are. If you are a real person using real numbers, the answer you want is -2.

Unfortunately, if you try to find the odd root of a negative number in OpenOffice Calc, it returns an error, because of a bug which has been present in OpenOffice since its creation: it uses logarithms to determine the root, which is perfectly fine, but it does not take into account the sign of the base, which is the bug.

This is a ridiculously easy to fix bug, and it mystifies me that the OpenOffice folks have let it stay broken for so long. However, there is a workaround:

SIGN(A1)*(ABS(A1)^(1/3))

What this does is find the cube root of the absolute value, and then applies the sign of the base against the result. Be careful with your parentheses.