The lazy numbers in R: correction
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Because of a change I did in the lazyNumbers package, I have to post a correction to my previous post.
The as.double
function, called on a lazy number, was not
stable. Now it is. In the previous post, the following equality was
true:
library(lazyNumbers) x <- 1 - lazynb(7) * 0.1 as.double(x) == 0.3 ## [1] FALSE
It is not true anymore. This is expected actually. Indeed, the double
numbers 0.1
and 0.3
do not exactly represent
the numbers \(0.1\) and
\(0.3\):
print(0.1, digits = 17L) ## [1] 0.10000000000000001 print(0.3, digits = 17L) ## [1] 0.29999999999999999
The double representation of whole numbers is exact. The following equality is true:
library(lazyNumbers) x <- 1 - lazynb(7) / 10 as.double(x) == 0.3 ## [1] TRUE
No other change, and nothing else to correct. It is time to submit the package to CRAN. See the Github repository for another short presentation of this package.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.