isreal

isreal(x) -> Bool

Test whether x or all its elements are numerically equal to some real number

Examples

  1. Check if a single value is real:

    julia> isreal(3.14)
    true
  2. Check if an array contains only real numbers:

    julia> arr = [1.0, 2.5, 3.7];
    julia> isreal(arr)
    true
  3. Check if a complex number is real:

    julia> complex_num = 2 + 0im;
    julia> isreal(complex_num)
    true
  4. Check if any element in an array is not real:
    julia> arr = [1.5, 2.5, 3 + 2im];
    julia> isreal(arr)
    false

Common mistake example:

julia> isreal([1, 2, "3"])
ERROR: MethodError: no method matching isreal(::Array{Any,1})

In this example, the array contains a non-numeric element ("3"), which causes an error. The isreal function works only on numeric values, so make sure to provide valid input to avoid such errors.

See Also

all, all!, angle, any, any!, falses, ifelse, is, isinf, isinteger, isnan, isperm, ispow2, isreal, trues,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: