beetlebug▾
/

tcl::mathfunc hypot

Gives the length of the hypotenuse of a right triangle.

tcl::mathfunc::hypot X Y
expr {hypot(X, Y)}

Description

Gives the square root of X squared plus Y squared: the distance of the point (X, Y) from the origin. It does not overflow for large arguments, so hypot(1e300, 1e300) is finite.

Arguments

ArgumentTypeDefaultDescription
XnumberrequiredOne side.
YnumberrequiredThe other side.

Returns

A float, 0 or more.

Examples

% expr {hypot(3, 4)}
5.0

% expr {hypot(1e300, 1e300)}
1.4142135623730952e+300

Errors

% expr {hypot(3)}
not enough arguments for math function "hypot"
-errorcode TCL WRONGARGS

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

# Tcl 8.6 only
% expr {hypot("x", 1)}
can't use non-numeric string as operand of "hypot"
-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