beetlebug▾
/

tcl::mathfunc pow

Gives a number to the power of another, as a float.

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

Description

Gives X raised to Y as a float, also for integer arguments. A negative X with a Y that has a fraction part is a domain error. A result too large for a double is Inf. For an exact integer power, use the operator **.

Arguments

ArgumentTypeDefaultDescription
XnumberrequiredThe base.
YnumberrequiredThe exponent.

Returns

A float.

Examples

% expr {pow(2, 10)}
1024.0

% expr {pow(9, 0.5)}
3.0

% expr {pow(2, -1)}
0.5

% expr {pow(2, 2000)}
Inf

Errors

% expr {pow(-8, 1.0/3)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}

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

Facts

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

See also