# Fun with std::pow and negative exponents

This topic is 4982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015826
×