$ZSQR (ObjectScript)
Returns the square root of a specified number.
Synopsis
$ZSQR(n)
Argument
Argument | Description |
---|---|
n | Any positive number, or zero. (The null string and nonnumeric string values are treated as a zero.) Can be specified as a value, a variable, or an expression. |
Description
$ZSQR returns the square root of n. It returns the square root of 1 as 1. It returns the square root of 0 and the square root of a null string ("") as 0. Specifying a negative number invokes an <ILLEGAL VALUE> error. You can use the absolute value function $ZABS to convert negative numbers to positive numbers.
Examples
The following example returns the square root of a user-supplied number.
READ "Input number for square root: ",num
IF num<0 { WRITE "ILLEGAL VALUE: no negative numbers" }
ELSE { WRITE $ZSQR(num) }
QUIT
Here are some specific examples:
WRITE $ZSQR(2)
returns 1.414213562373095049.
WRITE $ZSQR($ZPI)
returns 1.772453850905516027.