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.

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 on other sites
Wierd.

I think it's a conspiracy.

[smile]

Share on other sites
The built-in floating point C and C++ pows aren't meant to handle negative bases. They are described as

exp( power * log( base ) )

Share on other sites
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 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).

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• Forum Statistics

• Total Topics
632960
• Total Posts
3009473
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

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!