Thread Subject: strange sum result

Subject: strange sum result

From: Marco Pappalepore

Date: 27 Nov, 2007 10:43:58

Message: 1 of 3

if one writes in Matlab

>> 0.999999992 + 0.000000002

he gets

ans =

    9.999999940000001e-001

the strange result is that decimal 1 on the right.

Is that normal ? Is that IEEE-754 conformant ?

Where can I find the exact sum algorithm of matlab in order
to learn when to expect such a behaviour ?

many thanks

Subject: strange sum result

From: Kelvin Hales

Date: 27 Nov, 2007 11:19:05

Message: 2 of 3

In article <figsde$cj9$1@fred.mathworks.com>, Marco Pappalepore wrote:
> if one writes in Matlab
>
> >> 0.999999992 + 0.000000002
>
> he gets
>
> ans =
>
> 9.999999940000001e-001
>
> the strange result is that decimal 1 on the right.
>
> Is that normal ? Is that IEEE-754 conformant ?
>
> Where can I find the exact sum algorithm of matlab in order
> to learn when to expect such a behaviour ?
>
> many thanks

Not all decimal numbers have exact representations in binary, hence the
spurious '1' when calculating with a computer doing binary arithmetic.

Training in how binary digital computers do arithmetic, and how to
minimise the calculation errors that can therefore result from the
conversions from decimal > binary > decimal are (or at least were) an
integral part of most basic courses on computing - and an essential
knowledge for scientific and engineering users.

(Note that pocket calculators work in binary-coded-decimal, which is
accurate for decimal calculations.)

Subject: strange sum result

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 27 Nov, 2007 18:04:35

Message: 3 of 3

In article <figsde$cj9$1@fred.mathworks.com>,
Marco Pappalepore <crillion@tiscalinet.it> wrote:
>if one writes in Matlab

>>> 0.999999992 + 0.000000002

>he gets

>ans =

> 9.999999940000001e-001

>the strange result is that decimal 1 on the right.

>Is that normal ? Is that IEEE-754 conformant ?

Yes, it is normal, and yes, it is IEEE-754 conformant.


>Where can I find the exact sum algorithm of matlab in order
>to learn when to expect such a behaviour ?

You need to look up the documentation for your particular processor,
as processors implement IEEE-754 in different ways. You also
need to read IEEE-754 in more detail, as it documents a number
of different rounding modes that are legal.

Highly recommended is "What every computer scientist should know
about floating point arithmetic", by David Goldberg

http://portal.acm.org/ft_gateway.cfm?id=103163&type=pdf&coll=GUIDE&dl=GUIDE&CFID=44852402&CFTOKEN=33791253

or

http://docs.sun.com/source/806-3568/ncg_goldberg.html

or

http://www.freetechbooks.com/about592.html
--
   So you found your solution
   What will be your last contribution?
   -- Supertramp (Fool's Overture)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com