0

When I take the product of even integers from 2 to 40 in R, adding small numbers to the product doesn't appear to change the number.

So, getting that value with a for loop:

sum <- 1
for (i in 1:20){
j <- i*2
sum <- sum*j
}
> sum
[1] 2.551083e+24

Then, when I add numbers, the logical equivalence operator tells me the number isn't changing, e.g.

> sum == sum + 1
[1] TRUE

> sum == sum + 1e3
[1] TRUE
> sum == sum + 1e8
[1] TRUE
> sum == sum + 1e9
[1] FALSE

Why does this happen?

knl
  • 377
  • 2
  • 3
  • 9

0 Answers0