Swift Tutorial Swift References

Swift - tgamma() Function



The Swift tgamma() function returns gamma function of the argument. The gamma function of x is defined as:

tgamma
Gamma Function

Syntax

In Foundation framework, it is defined as follows:

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

Parameters

x Specify the value.

Return Value

Returns gamma function of the argument.

Example:

The example below shows the usage of tgamma() function.

import Foundation

print("tgamma(-2.5) = \(tgamma(-2.5))")
print("tgamma(-1.5) = \(tgamma(-1.5))")
print("tgamma(0.1) = \(tgamma(0.1))")
print("tgamma(1.5) = \(tgamma(1.5))")
print("tgamma(2.5) = \(tgamma(2.5))")

The output of the above code will be:

tgamma(-2.5) = -0.9453087204829418
tgamma(-1.5) = 2.363271801207355
tgamma(0.1) = 9.51350769866873
tgamma(1.5) = 0.886226925452758
tgamma(2.5) = 1.329340388179137

❮ Swift Math Functions