Swift Tutorial Swift References

Swift - fmin() Function



The Swift fmin() function returns minimum number between the two arguments.

Syntax

In Foundation framework, it is defined as follows:

public func fmin(_ lhs: CGFloat, _ rhs: CGFloat) -> CGFloat
public func fmin(_ lhs: Float, _ rhs: Float) -> Float
public func fmin(_ lhs: Float80, _ rhs: Float80) -> Float80
public func fmin(_ __x: Double, _ __y: Double) -> Double

Parameters

x, lhs Specify value to compare.
y, rhs Specify value to compare.

Return Value

Returns the numerically minimum value.

Example:

In the example below, fmin() function is used to find out the minimum value between the two arguments.

import Foundation

print("fmin(50.0, 100.0) = \(fmin(50.0, 100.0))")
print("fmin(50.0, -100.0) = \(fmin(50.0, -100.0))")
print("fmin(-50.0, 50.0) = \(fmin(-50.0, 50.0))")
print("fmin(-100.0, -50.0) = \(fmin(-100.0, -50.0))")

The output of the above code will be:

fmin(50.0, 100.0) = 50.0
fmin(50.0, -100.0) = -100.0
fmin(-50.0, 50.0) = -50.0
fmin(-100.0, -50.0) = -100.0

❮ Swift Math Functions