• Advertisement
Sign in to follow this  

Stupid math.

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Google: (-.5)^(1/3)= Output: -.5^(1 / 3) = -0.793700526 Mathomatic: (-.5)^(1/3) Output: answer = -0.793700525984 Maxima: bfloat((-.5)^(1/3)) Output: -7.93700525984099737375852819636154130195746663949926504904142880912608252812109586636772106631[...]B-1 C++: std::pow(-0.5, 1.0/3.0) Output: nan It would appear that 3 other sources are calling C++ a dirty liar.

Share this post


Link to post
Share on other sites
Advertisement
The problem is that there is 3 possible solutions; one is real and two are imaginary. C++ is using one of the imaginary solutions.

std::pow(std::complex<double>(-0.5), std::complex<double>(1.0/3.0)) gives me 0.39685+0.687365i.

I wanted the real one, that seemed like the obvious one to pick.

Share this post


Link to post
Share on other sites
I guess the best solution would be to check if the base is negative, and if it is use -((-base)^(1/3)) instead, which seems to give the (or one of the) right answer(s).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement