Why does Double reach `Double.infinity` BEFORE Double Max is reached?
<p>I wrote a tiny Swift programme to add a number to the previous number until it reached infinity. However, infinity is reached BEFORE the Double Maximum is reached.</p>

<ul>
<li>Double limit is 1.79769313486232e+308</li>
<li>Distance to limit is 4.90703911098917e+307</li>
<li>Yet, 8.07763763215622e+307 + 1.3069892237634e+308 reached infinity</li>
</ul>

<p>Why is this? (I answered this below.) </p>

<p>Run it for yourselves:</p>

<pre><code>import Foundation
import Darwin

var current: Double = 1
var previous: Double = 0
var register: Double = 0

var infinity = Double.infinity
var isInfinite = infinity.isInfinite

var n = 1
while current &lt; infinity {

    register = current
    current = previous + register
    print("\(n): \(current)")

    guard current != infinity else { break }

    previous = register

    n += 1
}

print("\n")
print("Double limit is \(DBL_MAX)")
print("Distance to limit is \(DBL_MAX - register)")
print("Yet, \(previous) + \(register) reached infinity")
</code></pre>