Swift Tutorial Swift Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Swift - erfc() Function



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

erfc function

Where, erf(x) is an error function. Error functions usually occur in probability, statistics and partial differential equation describing diffusion.

Complementary Error Function

Syntax

In Foundation framework, it is defined as follows:

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

Parameters

x Specify the value.

Return Value

Returns the complementary error function of the argument.

Example:

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

import Foundation

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

The output of the above code will be:

erfc(-2.0) = 1.9953222650189528
erfc(-1.0) = 1.842700792949715
erfc(0.0) = 1.0
erfc(1.0) = 0.15729920705028513
erfc(2.0) = 0.004677734981047265

❮ Swift Math Functions

5