[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] Bug in ns ? expr 100 + 0.1 returns 100.0999999999999 !!!!
Hi,
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 since 0.1 cannot be
accurately represented in binary digits you'll get the results you
described. And raw tcl behaves in the same way:
===
berkelium:~> tcl
tcl>expr 100.0 + 0.1
100.1
tcl>set tcl_precision 17
tcl>expr 100.0 + 0.1
100.09999999999999
tcl>
===
Matthias
On Tue, 16 Jan 2001, Thierry Ernst wrote:
> kunchanl wrote:
> >
> > try
> >
> > expr 100.0 + 0.1
>
> Thanks - I did try that to encounter the problem, but I am still
> surprised that "standard" TCL and "ns" TCL do not return the same value
> and I think this is a bug. If it's not, I would be glad to know the
> reason.
>
> Cheers,
> Thierry
>
>
> > > galibier:/home/glandon/ns/ns-all/ns-2.1b6> ./ns
> > > % expr 100 + 1
> > > 101
> > > % expr 100 + 0.1
> > > 100.09999999999999
> > > % expr 0.1 + 100
> > > 100.09999999999999
> > > % exit
> > > Mem:K User:1.02 Sys:0.09
> > > galibier:/home/glandon/ns/ns-all/ns-2.1b6> tcl
> > > tclsh tclsh7.4 tclsh7.5 tclsh8.0
> > > galibier:/home/glandon/ns/ns-all/ns-2.1b6> tclsh8.0
> > > % expr 100 + 1
> > > 101
> > > % expr 100 + 0.1
> > > 100.1
> > > % expr 0.1 + 100
> > > 100.1
> > > % exit
> > > galibier:/home/glandon/ns/ns-all/ns-2.1b6>
>