s-news
[Top] [All Lists]

strange sums

To: "S-News List" <s-news@lists.biostat.wustl.edu>
Subject: strange sums
From: John Fennick <jhf2@adelphia.net>
Date: Sat, 24 Sep 2005 13:50:34 -0400
Sorry about that, not a good day
john


Hi Group,

Using S-Plus version 7.2 under Win 2000
Can anyone explain this?

> sum(1.2, 2.8, 0.2, 3.2, 1.8)
[1] 9.2

> sum(-1.2, 2.8, -0.2, -3.2, 1.8)
[1] -2.220446e-016

# Same call with numbers concatenated (for amusement)
> sum(c(-1.2, 2.8, -0.2, -3.2, 1.8))
[1] -2.220446e-016

# Now: as a vector
> sum(as.vector(c(-1.2, 2.8, 0.2, -3.2, 1.8)))
[1] 0.4

(These were repeatable after shut down and cold restart.)

thanks

john

John Fennick
jhf2@adelphia.net
alt: j.fennick@ieee.org
Tel: 603.526.4023
134 Brookside Drive
New London, NH 03257
USA

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