R/is_natural_number.R

Defines functions is_natural_number

#' Detect whether the input is a natural number
#'
#' @param x The input.
#' @param tol The tolerance.
#'
#' @return
#' A Boolean variable indicating whether the input is a natural number.
#'
#' @keywords internal
#' @noRd
is_natural_number <- function(x, tol = .Machine$double.eps^0.5)
{
  return(is.numeric(x) && x > 0 && abs(x - round(x)) < tol)
}

Try the MMAD package in your browser

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

MMAD documentation built on March 12, 2026, 5:07 p.m.