- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 242字
- 2021-06-24 14:21:50
When are two values or objects equal or identical?
Whether two values are equal or not can be decided by the == operator, for example, 5 == 5 and 5 == 5.0 are both true. Equivalent to this operator is the isequal() function:
isequal(5, 5) #> true isequal(5, 5.0) #> true
Both the preceding statements return true, because objects such as numbers are immutable and they are compared at the bits level.
To see whether the two objects x and y are identical, they must be compared with the === operator. The result is a Bool value, true or false: x === y -> Bool, for example:
5 === 5 #> true
5 === 5.0 #> false
For objects that are more complex, such as strings, arrays, or objects that are constructed from composite types, the addresses in the memory are compared to check whether they point to the same memory location. For immutable object such as struct, this gets optimized so that instances with the same value point to the same object:
struct Vector3D
x::Float64
y::Float64
z::Float64
end
q = Vector3D(4.0, 3.14, 2.71)
r = Vector3D(4.0, 3.14, 2.71)
isequal(q, r) #> true
q === r #> true
However, if objects are mutable, they are different objects even if they have the same value, as follows:
mutable struct MVector3D
x::Float64
y::Float64
z::Float64
end
q = MVector3D(4.0, 3.14, 2.71)
r = MVector3D(4.0, 3.14, 2.71)
isequal(q, r) #> false
q === r #> false
- Getting Started with Citrix XenApp? 7.6
- 造個(gè)小程序:與微信一起干件正經(jīng)事兒
- Learning Elixir
- Learning Neo4j 3.x(Second Edition)
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- INSTANT Django 1.5 Application Development Starter
- 劍指MySQL:架構(gòu)、調(diào)優(yōu)與運(yùn)維
- ASP.NET Core 2 Fundamentals
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第二版)
- Practical Maya Programming with Python
- 嵌入式C編程實(shí)戰(zhàn)
- Mastering XenApp?
- 第五空間戰(zhàn)略:大國間的網(wǎng)絡(luò)博弈
- 前端Serverless:面向全棧的無服務(wù)器架構(gòu)實(shí)戰(zhàn)
- 基于Docker的Redis入門與實(shí)戰(zhàn)