Swift Double maximum()

The maximum() method returns the maximum of the given two values.

Example


maximum() Syntax

The syntax of the double maximum() method is:

double.maximum(firstValue, secondValue)

Here, double is an object of the Double class.


maximum() Parameters

The maximum() method takes two parameters

  • firstValue - a floating point value
  • secondValue - another floating point value

maximum() Return Values

  • returns the maximum element between firstValue and secondValue

Example 1: Swift Double maximum()

Output

20.0
25.78
60.1

In the above example, we have used the maximum() method find the largest among two provided floating point numbers.


Example 2: Swift Double and NaN (Not a Number)

Output

10.0
nan

Here, if we pass .nan as one of the parameters, the method will return the other value.

And, if we pass .nan for both the parameters, the method will return nan.