Swift - lgamma() Function
The Swift lgamma() function returns the natural logarithm of the absolute value of gamma function (log gamma function) of the argument. The log gamma function of x is defined as:
Syntax
In Foundation framework, it is defined as follows:
public func lgamma(_ x: CGFloat) -> CGFloat public func lgamma(_ x: Float) -> Float public func lgamma(_ x: Float80) -> Float80 public func lgamma(_ __x: Double) -> Double
Parameters
x |
Specify the value. |
Return Value
Returns the natural logarithm of the absolute value of gamma function of the argument.
Example:
The example below shows the usage of lgamma() function.
import Foundation print("lgamma(-2.5) = \(lgamma(-2.5))") print("lgamma(-1.5) = \(lgamma(-1.5))") print("lgamma(0.1) = \(lgamma(0.1))") print("lgamma(1.5) = \(lgamma(1.5))") print("lgamma(2.5) = \(lgamma(2.5))")
The output of the above code will be:
lgamma(-2.5) = -0.05624371649767407 lgamma(-1.5) = 0.8600470153764809 lgamma(0.1) = 2.2527126517342055 lgamma(1.5) = -0.12078223763524522 lgamma(2.5) = 0.2846828704729192
❮ Swift Math Functions