swh:1:snp:a4c99a50dc49f82b591f268001b320f8c3ca0041
Raw File
Tip revision: dc000f2a5f006d137f66716b086025d618bf8306 authored by John M Chambers on 14 July 2008, 00:00:00 UTC
version 1.0-5
Tip revision: dc000f2
binaryRep.R
binaryRep <-
function(data, m = .Machine$double.digits) {
    x <- data
    n <- length(x)
    
    xSign <- sign(x)
    x <- xSign * x
    exponent <- ifelse(x > 0, floor(1+log(x, 2)), 0)
    x <- x/2 ^ exponent
    pwrs <- binaryRepPowers(n, m)
    x <- matrix(x, n, m)
    xpwrs <- x * pwrs
    xrep <- trunc(xpwrs)/pwrs
    bits <- (xrep %*% binaryRepA(m)) *pwrs
    
    bits[] <- as.integer(bits[])
    new("binaryRep", original = data,
        sign = as.integer(xSign),
        exponent = as.integer(exponent),
        bits = binaryRepBits(bits))
}
back to top