How to find max value for Double and Float in Swift

Metropolis picture Metropolis · Feb 15, 2015 · Viewed 48.5k times · Source

Current learning Swift, there are ways to find max and min value for different kind of Integer like Int.max and Int.min.

Is there a way to find max value for Double and Float? Moreover, which document should I refer for this kind of question? I am currently reading Apple's The Swift Programming Language.

Answer

Vadoff picture Vadoff · Nov 11, 2016

As of Swift 3+, you should use:

CGFloat.greatestFiniteMagnitude
Double.greatestFiniteMagnitude
Float.greatestFiniteMagnitude