# adjust.s J F Monahan, June 2001 # write positive number in d*2**i format adjust <- function(x) { if( x <= 0 ) c( 0, -2**31 ) else { i <- 0 while (x > 16 ) { x <- x/16 i <- i + 4 } while (x < 1 ) { x <- x*16 i <- i - 4 } c(x,i) } } x <- c(13, -3, 128, .35, 257) ax <- c(sapply(x,adjust)) di <- t( matrix(c(ax),2,5) ) xdi <- paste( 'x', format(x), '= d*2**i ',format(di[,1]), format(di[,2])) cat(xdi,sep="\n") rm(list=ls())