beetlebug▾
/

tcl::mathfunc log2Tcl 9.1 only

Gives the logarithm of a number to the base 2.

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

Description

Gives the logarithm of NUMBER to the base 2. log2(0) is -Inf, and a negative number is a domain error.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredA number, 0 or more.

Returns

A float.

Examples

% expr {log2(8)}
3.0

% expr {log2(1024)}
10.0

% expr {log2(0)}
-Inf

Errors

% expr {log2(-1)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}

% expr {log2("x")}
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER

Facts

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

See also