Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AxoNeuron

macrumors 65816
Original poster
Apr 22, 2012
1,251
855
The Left Coast
Hey everyone. I am new to Objective-C programming. As a fun side project I am making a two dimensional representation of planetary orbits using actual data such as gravitational force, which require me to plug in values like the weight of the entire planet in kilograms, and the distance between the planets squared. This results in huge enormous numbers like 5.972x10^24.

Does anyone know how I should handle such large numbers? Trying to use int or float, of course, is out of the question.
 
The C type double can easily handle that. It's upper limit is a little less than 1.0E308, with about 16 decimal digits of precision, as I recall.

See here:
http://en.wikipedia.org/wiki/Double-precision_floating-point_format

If the double type won't work, then you need to be specific about why. For example, because you need more than the available precision, more than 1E308 dynamic range, etc.

You should also explain why float won't work, given its dynamic range.
 
Wow, I had assumed that my numbers were getting messed up because of limits with the numbers, but it turns out that I was incorrectly using the "pow" function. Thank you both VERY much!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.