tcl::mathfunc sqrt
Gives the square root of a number, as a float.
tcl::mathfunc::sqrt NUMBER
expr {sqrt(NUMBER)}
Description
Gives the square root of NUMBER as a float. A negative number is a domain error. An integer too large for a double gives Inf. For an exact square root of an integer, use isqrt.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| NUMBER | number | required | A number, 0 or more. |
Returns
A float, 0 or more.
Examples
% expr {sqrt(16)}
4.0
% expr {sqrt(2)}
1.4142135623730951
% expr {sqrt(10**400)}
Inf
Errors
% expr {sqrt(-1)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}
# Tcl 9.1 only
% expr {sqrt(NaN)}
cannot use non-numeric floating-point value "NaN" as operand of "sqrt"
-errorcode ARITH DOMAIN {non-numeric floating-point value}
# Tcl 8.6 only
% expr {sqrt(NaN)}
can't use non-numeric floating-point value as operand of "sqrt"
-errorcode ARITH DOMAIN {non-numeric floating-point value}
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1