beetlebug▾
/

tcl::mathfunc isqrt

Gives the integer square root of a number.

tcl::mathfunc::isqrt NUMBER
expr {isqrt(NUMBER)}

Description

Gives the largest integer whose square is at or below NUMBER. It is exact for an integer of any size. A float argument gives the integer square root of its integer part.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredA number, 0 or more.

Returns

An integer, 0 or more.

Examples

% expr {isqrt(17)}
4

% expr {isqrt(99)}
9

% expr {isqrt(10**40)}
100000000000000000000

% expr {isqrt(16.9)}
4

Errors

% expr {isqrt(-1)}
square root of negative argument
-errorcode NONE

# Tcl 9.1 only
% expr {isqrt("x")}
cannot use non-numeric string "x" as operand of "isqrt"
-errorcode ARITH DOMAIN {non-numeric string}

# Tcl 8.6 only
% expr {isqrt("x")}
can't use non-numeric string as operand of "isqrt"
-errorcode ARITH DOMAIN {non-numeric string}

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also