[ns] Bug in ns ? expr 100 + 0.1 returns 100.0999999999999 !!!!
Tue, 16 Jan 2001 11:46:50 -0800
On Tue, Jan 16, 2001 at 06:30:12PM +0000, Lloyd Wood wrote:
> On Tue, 16 Jan 2001, Heiler Matthias wrote:
> > It's not a real bug. In tcl/lib/ns-default.tcl you can find the line
> > ===
> > set tcl_precision 17
> > ===
> > which basically switches off rounding.
> ...and makes Tcl about as accurate as it can be; see the Tcl FAQ:
> Innocent question here. Given that ns has to bridge Tcl and C++,
> wouldn't it be nice if the arithmetical accuracy was the same high
> accuracy in both?
I think it is, since Tcl stores doubles as, well, doubles, internally,
unless one uses the string interface. The Tcl_Obj interface actually
does store doubles as doubles.
It looks like a major piece of work, though, to convert ns to use the
Tcl_Obj interface. I've used the Tcl_Obj interface for serializing
and unserializing my sim state, but I do have to convert argv in
the command() method to a Tcl_Obj list first.
The string interface is conceptually easier for most people to use,
but the Tcl_Obj interface is definitely more powerful. Although, I
can just see the number of questions cropping up on ns-users wrt
"my sim just crashed" and Tcl_Obj reference counting.