Skip to main content
Use the sqrt function in APL to compute the square root of a non-negative numeric value. sqrt is useful whenever you want to compress large numeric ranges, compute root-mean-square values, normalize metrics, or undo a squared transformation. It’s equivalent to pow(x, 0.5) but is more concise for the square-root case. If the input is negative, sqrt returns NaN (Not a Number). APL represents NaN as null in query results. Use isnan to filter these values before aggregating or charting.

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.
In Splunk SPL, sqrt() works identically: it takes a single numeric argument and returns its square root.
| eval root_duration = sqrt(req_duration_ms)
In ANSI SQL, SQRT() is a standard built-in function with the same semantics as in APL.
SELECT SQRT(req_duration_ms) AS root_duration FROM logs

Usage

Syntax

sqrt(x)

Parameters

NameTypeRequiredDescription
xrealYesThe value to compute the square root of. Must be non-negative for a defined result.

Returns

Returns the square root of x. If x is negative, the function returns NaN, which APL represents as null in query results. Use isnan to check for this condition.

Examples

Compute the square root of request duration

Use sqrt to normalize request durations by taking their square root, compressing the range of large values. Query
['sample-http-logs']
| extend root_duration = sqrt(req_duration_ms)
| project _time, id, req_duration_ms, root_duration
| order by root_duration desc
Run in Playground Output
_timeidreq_duration_msroot_duration
2024-11-14 10:00:00user-11600.040.0
2024-11-14 10:01:00user-2400.020.0
2024-11-14 10:02:00user-325.05.0

Detect NaN from negative inputs

When input values are negative, sqrt returns NaN. APL displays NaN as null. Use isnan to identify and handle these rows. Query
['sample-http-logs']
| extend shifted = req_duration_ms - 500
| extend root_shifted = sqrt(shifted)
| extend is_invalid = isnan(root_shifted)
| project _time, id, shifted, root_shifted, is_invalid
Run in Playground Output
_timeidshiftedroot_shiftedis_invalid
2024-11-14 10:00:00user-1700.026.46false
2024-11-14 10:01:00user-2-200.0nulltrue
2024-11-14 10:03:00user-3-50.0nulltrue
  • pow: Raises a value to an arbitrary power. sqrt(x) is equivalent to pow(x, 0.5).
  • isnan: Returns true when a value is NaN. Use it to detect null results from sqrt on negative inputs.
  • abs: Returns the absolute value. Use it to ensure inputs are non-negative before passing them to sqrt.
  • exp: Returns e^x. Use it when the inverse operation of log is needed rather than a root.
  • log: Returns the natural logarithm. Use it alongside sqrt when working in log space.