Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Double minimum()
In this tutorial, we will learn about the Swift Double minimum() method with the help of examples.
The minimum() method returns the minimum of the given two values.
Example
// return the smallest among 10 and 20
var result = Double.minimum(10,20)
print(result)
// Output: 10.0
minimum() Syntax
The syntax of the double minimum() method is:
double.minimum(firstValue, secondValue)
Here, double is an object of the Double class.
minimum() Parameters
The minimum() method takes two parameters
firstValue- a floating point valuesecondValue- another floating point value
minimum() Return Values
- returns the minimum element between
firstValueandsecondValue
Example 1: Swift Double minimum()
// return the smallest among 10 and 20
var result1 = Double.minimum(10,20)
print(result1)
// return the smallest among 20.8 and 25.78
var result2 = Double.minimum(20.8,25.78)
print(result2)
// return the smallest among 60.1 and 60
var result3 = Double.minimum(60,60.1)
print(result3)
Output
10.0 20.8 60.0
In the above example, we have used the minimum() method find the smallest among two provided floating point numbers.
Example 2: Swift Double and NaN (Not a Number)
// returns 10.0
var result1 = Double.minimum(10, .nan)
print(result1)
// returns nan
var result2 = Double.minimum(.nan, .nan)
print(result2)
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.
Did you find this article helpful?