Skip to contents

Returns TRUE if x is an integer vector, or a double vector whose values are exactly equal to their truncated form. See is_whole_number() to test for whole numbers within a chosen tolerance. See base::is.integer() to test for integer storage type.

Usage

is_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.

Examples

#----------------------------------------------------------------------------
# is_whole_numeric() examples
#----------------------------------------------------------------------------
library(bkbase)

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

# FALSE
is_whole_numeric(1.00000001)
#> [1] FALSE
is_whole_numeric(sqrt(2)^2)
#> [1] FALSE
is_whole_numeric(1 + 2^-30)
#> [1] FALSE

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