R/is.wholenumber.R

#' Determine whether number is integral or not.
#' 
#' Checks whether a numeric value is integral, up to machine or other specified
#' prescision.
#' 
#' 
#' @param x numeric vector to be tested.
#' @param tol The desired precision.
#' @return A logical vector of the same length as \code{x}, containing the
#' results of the test.
#' @author Robin Evans
#' @keywords arith
#' @examples
#' 
#' x = c(0.5, 1, 2L, 1e-20)
#' is.wholenumber(x)
#' 
#' @export is.wholenumber
is.wholenumber <-
function (x, tol = .Machine$double.eps^0.5) 
abs(x - round(x)) < tol

Try the rje package in your browser

Any scripts or data that you put into this service are public.

rje documentation built on Nov. 12, 2022, 9:06 a.m.