# chtab21.r September 2009, March 2010 # # floating point representations using sprintf and "%a" # # list of interesting numbers onep <- 1 + 2**(-16) # a little more than one full <- 2 - 2^(-52) # biggest with zero exponent # internal representation cbind(c(onep,full),sprintf("%a",c(onep,full))) nums <- c(2,1,1/16,0,-15,2**53-1, # exactly rep integer 2**53+1, # no longer exact 2**(-1022)*onep, # still normalized 2**(-1023)*onep, # just denormalized 2**(-1058)*onep, # very small positive 2**(-1074), # smallest positive 2**(-1075)*onep, # too small (2**1023)*onep, # almost biggest (2**1023)*full, # biggest (2**1024)*onep) # too big nums # names for those numbers names <- c("two","one","sixteenth","zero","neg fifteen", "exactly rep integer","no longer exact","still normalized", "just denormalized","very small positive","smallest positive", "too small", "almost biggest","biggest","too big") # internal representation internal <- sprintf("%a",nums) rbind(internal,nums,names) rm(list=ls()) q()