let highDouble = 1.7976931348623e+308 // Just under Double.greatestFiniteMagnitude
print(highDouble) // 1.7976931348623e+308
let highDecimal = Decimal(highDouble)
print(highDecimal) // 17976931348623005696000000000000000000000000000000000
This is not what I put in. For clarity, if I bring that back into a Double
:
let newHighDouble = Double(exactly: highDecimal as NSNumber)!
print(newHighDouble) // 1.7976931348623e+52
So a magnitude of 308 was reduced to only 52! What's going on here? I thought Decimal
could store extraordinarily large values, but it seems it can't even store what a Double
can!
Short snippet: Double(exactly: Decimal(1.7976931348623e+308) as NSNumber)!