Version 10 of Inf

Updated 2007-02-28 13:23:27

RS 2007-02-23: Inf is for infinity. From Tcl 8.5 it is a valid double (though not integer) value, as these experiments in an 8.5a4 tclkit show:

 (bin) 3 % set x [expr 1/0.]
 Inf
 (bin) 4 % expr $x+1
 Inf
 (bin) 5 % expr $x*$x
 Inf
 (bin) 6 % expr $x-$x
 domain error: argument not in valid range
 (bin) 7 % expr -$x
 -Inf
 (bin) 8 % expr -$x+$x
 domain error: argument not in valid range
 (bin) 9 % expr {$x+1 == $x}
 1

LV Note that this appears to be platform specific, since the various examples on this page don't produce the same results on a SPARC Solaris machine.


LV Besides expr. where else does a Tcl programmer need to worry about Inf (or NaN for that matter?) - RS: binary scan may return it for a double. A general test for Inf and Nan would be

 proc is'special'float x {expr {$x != $x || [catch {expr $x-$x}]}}

LV Can I also assume that if, because it does some expr like stuff, is another place one should be aware that Inf or NaN might show up? - RS: Easily tested, in 8.5a4:

 % set n [expr sqrt(-1)]
 -NaN
 % if {$n != $n} {puts YES}
 YES
 % set i [expr 1/0.]
 Inf
 % if {$i+1 == $i} {puts YES}
 YES

Category Glossary