Hey mathematicians, why is (odd integer) root of a negative number undefined behaviour?

_____
³√-27 = -3 ?
-3 · -3 = 9
9 · -3 = -27

Is this becoming a hobby of yours? You ask why something is not the way it should be, but it actually IS the way it should be. You can initialize multi-dimensional arrays in C or C++ to zero by specifying only the first element, and the odd-integer root of a negative number is perfectly well defined.

Here's some advice on how to ask questions on these forums:* Try to find the answer for yourself first. For instance, using Google. You do have an Internet connection, don't you?* If you still can't find the answer, post enough detail that we know what the situation is, why you think it's wrong, etc.

Let me illustrate what "enough detail" means:I tried to compute the cubic root of -27 in Windows Calculator [version blah] and I get an error message that would translate to "invalid value". Shouldn't the answer be -3? Is this a bug?

Actually it does in Windows 7's calculator. Windows calculator uses arbitrary precision numbers or it just performs symbolic optimization.

Regardless, I hadn't thought about floating point issues when doing the cubic root of a number in C++,so I am glad you pointed out that converting roots to powers is not a good idea when it comes to negative numbers, as a rule

Edited by Javier Meseguer de Paz, 03 April 2014 - 12:14 PM.

“We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil” - Donald E. Knuth, Structured Programming with go to Statements

"First you learn the value of abstraction, then you learn the cost of abstraction, then you're ready to engineer" - Ken Beck, Twitter