Swift Tutorial Swift References

Swift - erf() Function



The Swift erf() function returns the error function of the argument. The error function of x is defined as:

erf function

Error functions usually occur in probability, statistics and partial differential equation describing diffusion.

Error Function

Syntax

In Foundation framework, it is defined as follows:

public func erf(_ x: CGFloat) -> CGFloat
public func erf(_ x: Float) -> Float
public func erf(_ x: Float80) -> Float80
public func erf(_ __x: Double) -> Double

Parameters

x Specify the value.

Return Value

Returns the error function of the argument.

Example:

In the example below, erf() function returns the error function of the given value.

import Foundation

print("erf(-2.0) = \(erf(-2.0))")
print("erf(-1.0) = \(erf(-1.0))")
print("erf(0.0) = \(erf(0.0))")
print("erf(1.0) = \(erf(1.0))")
print("erf(2.0) = \(erf(2.0))")

The output of the above code will be:

erf(-2.0) = -0.9953222650189527
erf(-1.0) = -0.8427007929497149
erf(0.0) = 0.0
erf(1.0) = 0.8427007929497149
erf(2.0) = 0.9953222650189527

❮ Swift Math Functions