Learn R Programming

assertive (version 0.2-6)

assert_all_are_imaginary: Is the input real/imaginary?

Description

Checks to see if the input is real or imaginary.

Usage

assert_all_are_imaginary(x, tol = 100 * .Machine$double.eps)

assert_any_are_imaginary(x, tol = 100 * .Machine$double.eps)

assert_all_are_real(x, tol = 100 * .Machine$double.eps)

assert_any_are_real(x, tol = 100 * .Machine$double.eps)

is_imaginary(x, tol = 100 * .Machine$double.eps)

is_real(x, tol = 100 * .Machine$double.eps)

Arguments

x
Input to check.
tol
Imaginary/real components smaller than tol are not considered.

Value

  • TRUE if the input has imaginary component equal to zero. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

See Also

complex

Examples

Run this code
(x <- with(expand.grid(re = -1:1, im = -1:1), re + im * 1i))
is_real(x)
is_imaginary(x)

# By default, very small imaginary/real components are ignored.
x <- .Machine$double.eps * (1 + 1i)
is_real(x)
is_real(x, 0)
is_imaginary(x)
is_imaginary(x, 0)
assert_all_are_real(1:10)
assert_all_are_real(1:10 + 0i)
assert_any_are_real(c(1i, 0))
assert_all_are_imaginary(1:10 * 1i)
assert_any_are_imaginary(c(1i, 0))
dont_stop(assert_all_are_real(x))
dont_stop(assert_all_are_imaginary(x))

Run the code above in your browser using DataLab