Jump to content
  • Advertisement
Sign in to follow this  
silverphyre673

Fun with std::pow and negative exponents

This topic is 4822 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

I FINALLY (think) I figured out what is wrong with my gravity calculations... G = 6.67*(10^-11). std::pow() doesn't do negative exponents correctly, does it? I am 100% sure I just saw a post on this a couple days ago, but I can't find it. If I am to correctly represent 6.67 * (10^-11) how would I want to do that? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
pow() with negative exponents works fine for me. If you want to represent that number as a constant, though, just use 6.67e-11 .

Share this post


Link to post
Share on other sites
Er

(10 ^ -11) means: XOR the bits of 10 with the bits of -11.

10 = 1010b
-11 = 1s11....0101b

Answer = 1s11...1111b = -1.

Note: Nb means N is in binary.
Note: 1s = sign-bit is 1, meaning number is negative.


So overall, you had 6.67 * -1 = -6.67.



Share this post


Link to post
Share on other sites
Krylloan: If you'd read the OP's question, you'll notice he mentions std::pow() - the up-carrot symbol (^) is used to indicate "power of" in some other languages (BASIC I think among them), so the OP was probably just using it to indicate the forumla rather than what was actually used - otherwise the OP would be complaining about weird results with it rather than going on about std::pow.

silverphyre673:
#include <iostream>
using namespace std;

int main ( void ) {
float small = 6.67e-11;
float large = 1.0e+12;
cout << small * large << endl;
}


Result:
66.7
You probably allready know this since you said you were going to go try it, just posting this as proof that "yes, yes you can :-)" for the benifit of other posters :-).

Share this post


Link to post
Share on other sites
It is only negative fractional powers that it doesn't do, afaik.

OMG Krylloan, tell us you were kidding!

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!