x <- (1:20)*pi
stopifnot(ilogb (x) == logB (x), is.integer(ilogb(x)),
ilogb(-x) == logB(-x), is.double ( logB(x)))
cbind(x, "2^il(x)"= 2^logB(x), ilogb = ilogb(x), signbit = signbit(x),
fpclassify = fpclassify(x), isnormal = isnormal(x))
x <- c(2^-(10:22), rexp(1000));
summary(x / 2^ilogb(x)) # in [1, 2) interval
stopifnot(nearbyint(x) == round(x))
nextafter(-0, +0)
nextafter(+0, 1)
nextafter(+0, -1)
nextafter(Inf, -1)
nextafter(-Inf, 0)
Run the code above in your browser using DataLab