12.7.7         TYPES, OVERFLOW, AND PRECISION

All internal computations involving integers are done with the C type long, and all internal computations involving floating-point are done with the C type double. When converting a string to floating-point, exponent overflow is detected and results in a Tcl error. For conversion to integer from string, detection of over-flow depends on the behavior of some routines in the local C library, so it should be regarded as unreliable.

In any case, integer overflow and underflow are generally not detected reliably for intermediate results. Floating-point overflow and underflow are detected to the degree supported by the hardware, which is generally pretty reliable.

Conversion among internal representations for integer, floating-point, and string operands is done automatically

as needed. For arithmetic computations, integers are used until some floating-point number is introduced, after which floating-point is used. For example,

expr 5 / 4

returns 1,

while 

expr 5 / 4.0

expr 5 / ( [string length "abcd"] + 0.0 )

both return 1.25.

 

Floating-point values are always returned with a ‘‘.’’ or an e so that they will not look like integer values. For example,

expr 20.0/5.0

returns 4.0, not 4.