tcl::mathfunc bool
Gives 1 or 0 for a boolean value or a number.
tcl::mathfunc::bool VALUE
expr {bool(VALUE)}
Description
Gives 1 for a true value and 0 for a false value. A number is false when it is zero, so bool(0.5) is 1 and bool(0.0) is 0. A text is a boolean of Tcl: yes, true, and on are 1, and no, false, and off are 0.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VALUE | boolean or number | required | A number or a boolean word. |
Returns
1 or 0.
Examples
% expr {bool("yes")}
1
% expr {bool("off")}
0
% expr {bool(2)}
1
% expr {bool(0.0)}
0
Errors
% expr {bool("x")}
expected boolean value but got "x"
-errorcode TCL VALUE NUMBER
% expr {bool()}
not enough arguments for math function "bool"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1