[R] problem with sum function

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 1 22:55:55 CET 2012


Of course there's rounding error: your computer can't
store those decimal numbers precisely. See R FAQ 7.31 for
details.

See also:
sum(10*c(-0.2, 0.8, 0.8, -3.2, 1.8)) / 10

Sarah

On Thu, Mar 1, 2012 at 4:49 PM, Mark A. Albins <kamokoi55 at gmail.com> wrote:
> Hi!
>
> I'm running R version 2.13.0 (2011-04-13)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> When i type in the command:
>
> sum(c(-0.2, 0.8, 0.8, -3.2, 1.8))
>
> R returns the value:
>
> -5.551115e-17
>
> Why doesn't R return zero in this case?  There shouldn't be any rounding
> error in a simple sum.
>
> Thanks,
>
> Mark

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list