0

According to Swift, the greatest finite magnitude that can be stored as a Double is much more than that of Int.

print(Double.greatestFiniteMagnitude) // 1.7976931348623157e+308

However, the accepted answer to this question says that you may lose precision while storing large values.

So, what is the maximum value that can be saved as a Double without losing precision?

rmaddy
  • 298,130
  • 40
  • 468
  • 517
Nilanshu Jaiswal
  • 1,265
  • 3
  • 15
  • 31
  • Is this a real world problem or are you just curious? Either way, did you read the articles linked to in the answer you linked to? – Joakim Danielson Nov 18 '19 at 12:50
  • @JoakimDanielson I want to calculate very long factorials. There is a limitation in using Int. This great answer https://stackoverflow.com/q/43830151/8330469 gives the solution. But, if Double can store very large values, we can calculate large factorials more easily. I had a cursory look at the articles but I didn't go deep. The articles are too deep and right now I can't go so deep. So, I decided to put this as a question here. It may help others in future as well who may be constrained by time to do thorough research on floats and hence may seek answers in Stackoverflow. Thanks a lot :) – Nilanshu Jaiswal Nov 18 '19 at 17:05
  • 1
    A `Double` is good for 15 or 16 significant digits. – rmaddy Nov 18 '19 at 17:30

0 Answers0