Skip to contents

Returns TRUE if x is a single whole number to some tolerance. See is_scalar_whole_numeric() to test for a scalar whole number without a tolerance. See base::is.integer() to test for integer storage type.

Usage

is_scalar_whole_number(x, tol = 1e-08)

Arguments

x

The object to be tested.

tol

(Scalar numeric: 1e-08; [0, Inf))
Absolute differences smaller than tol are ignored, thus assumed to be a whole number.

Value

Scalar logical

Details

  • NA, NaN, Inf, and -Inf return FALSE.

  • Zero-length input and NULL return FALSE.

  • Inputs with length other than 1 return FALSE.

Examples

#----------------------------------------------------------------------------
# is_scalar_whole_number() examples
#----------------------------------------------------------------------------
library(bkbase)

# TRUE
is_scalar_whole_number(1L)
#> [1] TRUE
is_scalar_whole_number(1)
#> [1] TRUE
is_scalar_whole_number(9.0)
#> [1] TRUE
is_scalar_whole_number(sqrt(2)^2)
#> [1] TRUE
is_scalar_whole_number(1 + 2^-30)
#> [1] TRUE
is_scalar_whole_number(1e100)
#> [1] TRUE
is_scalar_whole_number(1.00000001)
#> [1] TRUE

# FALSE
is_scalar_whole_number(1.0000001)
#> [1] FALSE
is_scalar_whole_number(Inf)
#> [1] FALSE
is_scalar_whole_number(c(1, 2, 3))
#> [1] FALSE

# Missing values and zero-length
is_scalar_whole_number(NA_integer_) # FALSE
#> [1] FALSE
is_scalar_whole_number(NA_real_)    # FALSE
#> [1] FALSE
is_scalar_whole_number(NaN)         # FALSE
#> [1] FALSE
is_scalar_whole_number(numeric(0))  # FALSE
#> [1] FALSE
is_scalar_whole_number(NULL)        # FALSE
#> [1] FALSE