loggamma function in APL to compute the natural logarithm of the absolute value of the gamma function. This is equivalent to log(abs(gamma(x))) but avoids the numeric overflow that occurs when gamma(x) itself becomes too large to represent as a floating-point number.
loggamma is useful when you work with large inputs to the gamma function in statistical calculations, such as log-likelihood computations, Bayesian modeling, or custom anomaly scoring. Use it whenever gamma(x) would overflow to infinity.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
Splunk SPL doesn’t include a built-in
loggamma() function. You typically implement it using external libraries or the Machine Learning Toolkit.ANSI SQL users
ANSI SQL users
Standard SQL does not define a
LOGGAMMA() function. You need to implement it in application code or through database-specific extensions.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | real | Yes | The input value. Must not be zero or a negative integer. |
Returns
The natural logarithm of the absolute value of the gamma function ofx.
Example
Useloggamma to compute the log-gamma value of a duration in seconds without risking numeric overflow.
Query
| _time | id | req_duration_ms | loggamma_val |
|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 1000.0 | 0.0000 |
| 2024-11-14 10:01:00 | user-2 | 2000.0 | 0.0000 |
| 2024-11-14 10:02:00 | user-3 | 10000.0 | 16.1181 |
List of related functions
- gamma: Returns the gamma function directly. Use it for small inputs where overflow is not a concern.
- log: Returns the natural logarithm. Use it for general log-transformation without the gamma relationship.
- exp: Returns e^x. Use it to exponentiate
loggammaresults back to the original gamma scale when the values are small enough. - isfinite: Returns whether a value is finite. Use it to verify that
loggammaresults are valid for downstream calculations. - abs: Returns the absolute value. Note that
loggamma(x)equalslog(abs(gamma(x))), soabsis implicitly applied togamma(x)before the log.