[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 20:58:20 +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: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)
- Exact zero, Patrick Carle, 2011/05/27
- Re: Exact zero,
Martin Helm <=