Skip to main content
Use the 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 doesn’t include a built-in loggamma() function. You typically implement it using external libraries or the Machine Learning Toolkit.
| eval loggamma_val = null()
Standard SQL does not define a LOGGAMMA() function. You need to implement it in application code or through database-specific extensions.
-- No standard SQL equivalent; use application code
SELECT NULL AS loggamma_val FROM logs

Usage

Syntax

loggamma(x)

Parameters

NameTypeRequiredDescription
xrealYesThe input value. Must not be zero or a negative integer.

Returns

The natural logarithm of the absolute value of the gamma function of x.

Example

Use loggamma to compute the log-gamma value of a duration in seconds without risking numeric overflow. Query
['sample-http-logs']
| where req_duration_ms > 0
| extend duration_s = req_duration_ms / 1000.0
| extend loggamma_val = loggamma(duration_s)
| project _time, id, req_duration_ms, loggamma_val
Run in Playground Output
_timeidreq_duration_msloggamma_val
2024-11-14 10:00:00user-11000.00.0000
2024-11-14 10:01:00user-22000.00.0000
2024-11-14 10:02:00user-310000.016.1181
  • 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 loggamma results back to the original gamma scale when the values are small enough.
  • isfinite: Returns whether a value is finite. Use it to verify that loggamma results are valid for downstream calculations.
  • abs: Returns the absolute value. Note that loggamma(x) equals log(abs(gamma(x))), so abs is implicitly applied to gamma(x) before the log.