[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exact zero
From: |
Martin Helm |
Subject: |
Re: Exact zero |
Date: |
Fri, 27 May 2011 21:24:11 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Am Freitag, 27. Mai 2011, 20:58:20 schrieb Martin Helm:
> Am Freitag, 27. Mai 2011, 20:43:38 schrieb Patrick Carle:
> > This prints a list of numbers, one of which is exactly zero :
> >
> > fprintf('%.1e\n',((3:14)-14/2)*.01);
> >
> > But when the 3 is changed to a 2 in ie:
> >
> > fprintf('%.1e\n',((2:14)-14/2)*.01);
> >
> > The number that used to be exactly zero is now -1.7e-018. Is this a bug?
> > Is there a way to force this to be exactly zero?
> >
> > Thanks!
>
> 0.01 can not be represented in IEEE 754 floating point, this leads to
> rounding errors. And no - it is not a bug.
>
> A simple introduction is this
> http://en.wikipedia.org/wiki/Floating_point
> (Representable numbers, conversion and rounding)
Ah sorry, I looked more in detail into it, are you sure?
I cannot see that with 3.4 and it should not happen with this statement since
(2:14)-14/2) is a sequence of exact integer values afterwards multiplied by
0.01.
Which version are you using and on which operating system?