beetlebug▾
/

tcl::mathop compare

The commands of the operators that compare values as numbers, or as strings when they are not numbers.

tcl::mathop::== ?VALUE ...?
tcl::mathop::!= VALUE VALUE
tcl::mathop::< ?VALUE ...?
tcl::mathop::<= ?VALUE ...?
tcl::mathop::> ?VALUE ...?
tcl::mathop::>= ?VALUE ...?

Description

Two values that are both numbers compare as numbers, so == 0x10 16 is 1. Otherwise they compare as strings, in the order of the code points of their characters.

==, <, <=, >, and >= accept any count of arguments and give 1 when each pair of neighbor arguments is in the relation: < 1 2 3 is 1. With no argument or one argument they give 1. != needs exactly two arguments.

NaN is a number that equals no number, also itself: == NaN NaN is 0, and < 1 NaN is 0.

Arguments

ArgumentTypeDefaultDescription
VALUEnumber or stringrequiredA value to compare.

Returns

1 or 0.

Examples

% tcl::mathop::== 1 1.0 1
1

% tcl::mathop::== 0x10 16
1

% tcl::mathop::!= 1 2
1

% tcl::mathop::< 1 2 3
1

% tcl::mathop::< 1 3 2
0

# Two numbers compare as numbers.
% tcl::mathop::< 10 9
0

# A value that is not a number makes a comparison of strings.
% tcl::mathop::< 10 abc
1

% tcl::mathop::<= 1 2 2 3
1

% tcl::mathop::>= 3 3 1
1

% tcl::mathop::<
1

% tcl::mathop::== NaN NaN
0

# Tcl 9.1 only
# In Tcl 9.1, 08 is the decimal number 8.
% tcl::mathop::== 08 8
1

# Tcl 8.6 only
# In Tcl 8.6, 08 is not an octal number, so the two compare as strings.
% tcl::mathop::== 08 8
0

Errors

% tcl::mathop::!= 1
wrong # args: should be "tcl::mathop::!= value value"
-errorcode TCL WRONGARGS

% tcl::mathop::!= 1 2 3
wrong # args: should be "tcl::mathop::!= value value"
-errorcode TCL WRONGARGS

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