Why is the odd integer rootof a negative number undefined?

Started by
11 comments, last by jmpep 10 years ago


instead of 1/3 (since otherwise it would raise it to the first and then divide by three)

Either you're not using parentheses correctly, or your calculator is badly broken. Parenthetical expressions are evaluated first and the calculation should reduce to -270.333..

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

It is a problem of the Windows Vista Calculator then. In Windows 7 it works perfectly.

Just out of curiosity, try: (-27)^(1/3) in the calculator to see if you get an answer.

That won't work. If you compute 1/3 as a floating-point number it will be rounded to some fraction with a power of 2 in the denominator, and now -27 raised to that power won't be a real number.

In C99 and C++11 you have the function `cbrt', which will give you the correct value, but if you use `pow', you'll get `nan'.


That won't work

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 smile.png

“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

This topic is closed to new replies.

Advertisement