beetlebug▾
/

tcl::mathfunc int

Gives the integer part of a number.

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

Description

Cuts the fraction part off NUMBER, toward zero.

In Tcl 9.1 the result is an integer of any size, as with entier. In Tcl 8.6 the result keeps the low 64 bits, as with wide, so a value of 2**63 or more wraps around.

Arguments

ArgumentTypeDefaultDescription
NUMBERnumberrequiredAn integer or a finite float.

Returns

An integer.

Examples

% expr {int(3.9)}
3

% expr {int(-3.9)}
-3

# Tcl 9.1 only
% expr {int(1e20)}
100000000000000000000

# Tcl 8.6 only
% expr {int(1e20)}
7766279631452241920

Errors

% expr {int(Inf)}
integer value too large to represent
-errorcode NONE

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

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

Tcl 8.6 and Tcl 9.1

Facts

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

See also