is(x,y)
is(x, y) -> Bool ===(x,y) -> Bool ≡(x,y) -> Bool
Determine whether x and y are identical, in the sense that no program could distinguish them. Compares mutable objects by address in memory, and compares immutable objects (such as numbers) by contents at the bit level. This function is sometimes called egal.
Examples
-
Check if two objects are identical:
julia> is(10, 10) trueThis example demonstrates that the two integer objects
10are identical. -
Compare strings for identity:
julia> is("hello", "hello") trueIt checks if the two string objects
"hello"are identical. -
Identical arrays:
julia> arr1 = [1, 2, 3]; julia> arr2 = [1, 2, 3]; julia> is(arr1, arr2) falseIn this example, the
isfunction returnsfalsebecausearr1andarr2are different array objects, even though they have the same content. - Immutable objects equality:
julia> is(3.14, 3.1400000000000001) falseThe
isfunction compares immutable objects at the bit level. In this example, the two floating-point numbers are not considered identical due to slight differences in their binary representation.
It's worth noting that === and ≡ are aliases for the is function, so they can be used interchangeably.
Please remember that is compares mutable objects by memory address and immutable objects by bit-level contents. Avoid using is for comparing mutable objects' content as it may not give the expected results.
If you encounter any issues or unexpected behavior when using is, ensure that you are comparing the correct types and objects.
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.