Skip to contents

Returns TRUE if x is a single integer, or a single double whose value is exactly equal to its truncated form. See is_scalar_whole_number() to test for a scalar whole number within a chosen tolerance. See base::is.integer() to test for integer storage type.

Usage

is_scalar_whole_numeric(x)

Arguments

x

The object to be tested.

Value

Scalar logical

Details

  • Inf and -Inf in double storage return TRUE because Inf == trunc(Inf).

  • NA and NaN return FALSE.

  • Zero-length input and NULL return FALSE.

  • Inputs with length other than 1 return FALSE.

Examples

#----------------------------------------------------------------------------
# is_scalar_whole_numeric() examples
#----------------------------------------------------------------------------
library(bkbase)

# TRUE
is_scalar_whole_numeric(1L)
#> [1] TRUE
is_scalar_whole_numeric(1)
#> [1] TRUE
is_scalar_whole_numeric(9.0)
#> [1] TRUE
is_scalar_whole_numeric(1e100)
#> [1] TRUE
is_scalar_whole_numeric(Inf)
#> [1] TRUE

# FALSE
is_scalar_whole_numeric(1.00000001)
#> [1] FALSE
is_scalar_whole_numeric(sqrt(2)^2)
#> [1] FALSE
is_scalar_whole_numeric(1 + 2^-30)
#> [1] FALSE
is_scalar_whole_numeric(c(1, 2, 3))
#> [1] FALSE

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