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.Splunk SPL users
Splunk SPL users
In Splunk SPL,
sqrt() works identically: it takes a single numeric argument and returns its square root.ANSI SQL users
ANSI SQL users
In ANSI SQL,
SQRT() is a standard built-in function with the same semantics as in APL.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | real | Yes | The value to compute the square root of. Must be non-negative for a defined result. |
Returns
Returns the square root ofx.
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
Usesqrt to normalize request durations by taking their square root, compressing the range of large values.
Query
| _time | id | req_duration_ms | root_duration |
|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 1600.0 | 40.0 |
| 2024-11-14 10:01:00 | user-2 | 400.0 | 20.0 |
| 2024-11-14 10:02:00 | user-3 | 25.0 | 5.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
| _time | id | shifted | root_shifted | is_invalid |
|---|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 700.0 | 26.46 | false |
| 2024-11-14 10:01:00 | user-2 | -200.0 | null | true |
| 2024-11-14 10:03:00 | user-3 | -50.0 | null | true |
List of related functions
- pow: Raises a value to an arbitrary power.
sqrt(x)is equivalent topow(x, 0.5). - isnan: Returns
truewhen a value is NaN. Use it to detectnullresults fromsqrton 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
logis needed rather than a root. - log: Returns the natural logarithm. Use it alongside
sqrtwhen working in log space.