Enormous Numbers

Discussion in 'iOS Programming' started by AxoNeuron, Sep 4, 2014.

  1. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #1
    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.
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    An IEEE-754 float is good up to a little bit over 10^38
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. AxoNeuron thread starter macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #4
    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!!!
     

Share This Page