Re: for problem...
From: Donal K. Fellows (donal.k.fellows_at_man.ac.uk)
Date: 12/02/03
- Next message: newexpectuser: "How do I check for a message with quotes in an EXPECT script"
- Previous message: Ulrich Schoebel: "Re: Silent overriding of the command (reopened)"
- Maybe in reply to: David Cobac: "Re: for problem..."
- Next in thread: David Cobac: "Re: for problem..."
- Reply: David Cobac: "Re: for problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 2 Dec 2003 05:58:20 -0800
Donald Arseneau wrote:
> Removing the braces is not supposed to make a difference, thus there
> is TIP#132 proposing to change the default tcl_precision to 17.
Actually, IIRC #132 proposes altering the number formatting code so
that it generates the minimal representation of a floating-point
number in the normal case. (Unfortunately, it turns out that the
library we were going to rely on for doing this is a real mess, so the
work got a bit shelved...)
The original problem basically stems from the fact that Tcl (as with
most other computer programs) is representing 0.01 as a little bit
more than that value (it doesn't have a precise representation.)
Normally this doesn't matter, but it does when you decide to compare
the sum of a hundred of those values with 1.0. This is fundamental to
finite-precision floating-point numbers; you have similar problems
representing thirds in decimal, except there you tend to get totals
too small:
1/3 = 0.333 (three decimal places for this example)
Now 1/3+1/3+1/3 = 1
so 0.333+0.333+0.333 ought to be 1 too, but it is really 0.999
So if you were doing a loop while you were less than one, you'd loop
one time more (i.e. with the value 1.332) which is surprising if
you're one of these people who ignores representation limitations...
Donal (this sort of thing has been in the computer literature since at
least the time I got my first computer, when it was already a
well-known phenomenon.)
- Next message: newexpectuser: "How do I check for a message with quotes in an EXPECT script"
- Previous message: Ulrich Schoebel: "Re: Silent overriding of the command (reopened)"
- Maybe in reply to: David Cobac: "Re: for problem..."
- Next in thread: David Cobac: "Re: for problem..."
- Reply: David Cobac: "Re: for problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|