Search code examples
swiftfloating-pointintdoubleinfinity

How to find max value for Double and Float in Swift


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.


Solution

  • As of Swift 3+, you should use:

    CGFloat.greatestFiniteMagnitude
    Double.greatestFiniteMagnitude
    Float.greatestFiniteMagnitude