Fun with std::pow and negative exponents

Started by
4 comments, last by iMalc 18 years, 10 months ago
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.
my siteGenius is 1% inspiration and 99% perspiration
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 .
you can't just type that in, can you... let me try!
my siteGenius is 1% inspiration and 99% perspiration
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.



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

OMG Krylloan, tell us you were kidding!
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement