# 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 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 on other sites
you can't just type that in, can you... let me try!

##### Share on other sites
Er

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

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

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 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 on other sites
It is only negative fractional powers that it doesn't do, afaik.

OMG Krylloan, tell us you were kidding!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628356
• Total Posts
2982252

• 10
• 9
• 13
• 24
• 11