[R] Numbers that look equal, should be equal, but if() doesn't see as equal (repost with code included)

Duncan Murdoch dmurdoch at pair.com
Wed May 28 20:58:35 CEST 2003


On Wed, 28 May 2003 15:59:45 +0100 (BST), Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:


>> print(c(0.1 + 0.2, 0.3), digits=20)
>[1] 0.30000000000000004 0.29999999999999999
>
>yet
>
>> print(c(0.1, 0.2, 0.3), digits=20)
>[1] 0.1 0.2 0.3

Is this the way things should work?  Why isn't 0.3 printed as
0.30000000000000000 the first time, or as 0.29999999999999999 the
second time?  Surely its value is the same in both print statements,
and the requested format is the same in both.  

Duncan Murdoch




More information about the R-help mailing list