Jump to content
  • Advertisement
Sign in to follow this  
smart_idiot

Stupid math.

This topic is 4889 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!