beetlebug▾
/

tcl::mathfunc remainderTcl 9.1 only

Gives the remainder of a division with the quotient rounded to the nearest integer.

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

Description

Gives X minus Y times the quotient X/Y rounded to the nearest integer, with a half rounded to the even integer. The result can be negative for positive arguments: remainder(7, 2) is -1.0, since 3.5 rounds to 4. A zero Y or an infinite X is a domain error.

Arguments

ArgumentTypeDefaultDescription
XnumberrequiredThe dividend.
YnumberrequiredThe nonzero divisor.

Returns

A float, at most half of Y in magnitude.

Examples

% expr {remainder(7, 2)}
-1.0

% expr {remainder(-7, 2)}
1.0

% expr {remainder(7.5, 2)}
-0.5

% expr {remainder(7, Inf)}
7.0

Errors

% expr {remainder(7, 0)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}

% expr {remainder(Inf, 2)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}

Facts

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

See also