s-news
[Top] [All Lists]

Re: strange round / signif behaviour

To: Pierre Delfosse <pierre.delfosse@centexbel.be>
Subject: Re: strange round / signif behaviour
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Wed, 25 Jul 2001 14:16:35 +0100 (BST)
Cc: <s-news@wubios.wustl.edu>
In-reply-to: <C1B1A78EB953D211902D0040056AC48B6477@VRVCOM>
On Wed, 25 Jul 2001, Pierre Delfosse wrote:

> Dear S+ users,
>
> S+ 2000 under W98 does not always "round" nor "signif" correctly. For
> example,
>
>       > round(0.81,2)
>       [1] 0.8100000000000001
>       > signif(0.81,2)
>       [1] 0.8100000000000001
>
> (there are other examples).
>
> Is this a known bug, possibly computer dependant? How can I avoid this
> behaviour?

Well, 0.81 is not exactly representable in binary arithmetic, so a binary
computer cannot round to a number of decimal places exactly.

What you are seeing seems to be a bug in the Windows C run-time library,
*unless* you changed the `digits' option to display more than 7
significant figures.

On S+6.0, Linux, I get

> round(0.81,2)
[1] 0.81
> options(digits=16)
> round(0.81,2)
[1] 0.8100000000000001

which suggests you did not tell us the whole story.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>