expansions
packageExpansions of integer and real numbers, and odometers.
To install on Windows:
devtools::find_rtools()
devtools::install_github('stla/expansions', build_vignettes=TRUE)
On Linux:
devtools::install_github('stla/expansions', build_vignettes=TRUE)
n <- 14
(n_to_base3 <- intAtBase(n, base=3) )
## [1] 2 1 1
sum(n_to_base3*c(1,3,3^2)) == n
## [1] TRUE
# Cartesian product {0,1}x{0,1,2}x{0,1}:
sapply(0:11, function(x) intToAry(x, sizes=c(2,3,2)))
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 0 1 0 1 0 1 0 1 0 1 0 1
## [2,] 0 0 1 1 2 2 0 0 1 1 2 2
## [3,] 0 0 0 0 0 0 1 1 1 1 1 1
x <- 0.625
( x_to_base2 <- floatExpand01(0.625, base=2) )
## [1] 1 0 1
sum(x_to_base2 / 2^(1:3)) == x
## [1] TRUE
x <- 1.125
( x_to_base2 <- floatExpand(1.125, base=2) )
## $digits
## [1] 1 0 0 1
##
## $exponent
## [1] 1
sum(x_to_base2$digits / 2^(1:4)) * 2^x_to_base2$exponent == x
## [1] TRUE
odometer(c(1,0,1), base=2)
## [1] 0 1 1
sumadic(c(0,1,1), c(1,0,1), base=2)
## [1] 1 1 0 1
http://stla.github.io/stlapblog/posts/expansions_package.html
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.