sqrt()
Returns the positive square root of the specified number.
Syntax
sqrt(NUM_EXPR)
Parameters
NUM_EXPR- The number whose square root is to be computed. Must be a numeric type.
Description
The sqrt() function returns the positive square root of NUM_EXPR as a 64-bit double. Internally uses Math.sqrt().
Returns null if NUM_EXPR is null or not a numeric type. Returns NaN if the input is negative.
Error codes
N/A
Usage examples
-
Calculate the square root of 4.
json "{}" | eval s = sqrt(4) | # s: 2.0 -
Calculate the square root of 2.
json "{}" | eval s = sqrt(2) | # s: 1.4142135623730951 -
A negative input returns NaN.
json "{}" | eval s = sqrt(-1) | # No result (NaN cannot be serialized to JSON, so an empty result is returned) -
NULL input
json "{}" | eval s = sqrt(null) | # s: null
Compatibility
The sqrt() function is available since before Sonar 4.0.