Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 234
X.Creates Avatar asked Feb 15 '15 11:02

X.Creates


People also ask

What is the max value of a double?

The value of this constant is positive 1.7976931348623157E+308.

What is double value in Swift?

Double represents a 64-bit floating-point number. Double has a precision of at least 15 decimal digits, whereas the precision of Float can be as little as 6 decimal digits. Swift always chooses Double (rather than Float) when inferring the type of floating-point numbers.


1 Answers

As of Swift 3+, you should use:

CGFloat.greatestFiniteMagnitude Double.greatestFiniteMagnitude Float.greatestFiniteMagnitude 
like image 89
Vadoff Avatar answered Sep 24 '22 20:09

Vadoff