Daddy Clanger (imc) wrote,
Daddy Clanger
imc

And finally…

A tcl stupidity.

Let c be an arbritrary number. When does c2 not equal c2?

In tcl 8.0:
% set c 64.5165238678
64.5165238678
% set a [expr $c * $c]
4162.38185198
% set b $a
4162.38185198
% expr $b - $c * $c
0.0


So far, if we set b to c2 then b-c2 is zero. Makes sense, yes?

% $a
invalid command name "4162.38185198"
% expr $b - $c * $c
-4.40741132479e-09


And now it's magically not zero!

In tcl 8.4.4 the rules are slightly different: as soon as you set b=c2, the value of b-c2 is not zero - you don't need the $a trick*. And that's why my program dies (invalid argument to the sqrt function) when it tries to compute the standard deviation of a set which happens to contain only one element.

* Any command which treats $a as a list will also do, such as llength $a.
Subscribe

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments