Sign in to follow this  
silverphyre673

Fun with std::pow and negative exponents

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this