{"id":3171,"date":"2023-07-23T15:48:04","date_gmt":"2023-07-23T10:18:04","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=3171"},"modified":"2023-07-23T15:48:04","modified_gmt":"2023-07-23T10:18:04","slug":"the-operator-in-julia","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2023\/07\/23\/the-operator-in-julia\/","title":{"rendered":"The &#8220;===&#8221; Operator in Julia"},"content":{"rendered":"<p>In addition to the conventional &#8220;<em><strong>==&#8221;<\/strong><\/em> operator that checks if two objects are <em><strong>equal<\/strong><\/em>, <em><strong>Julia<\/strong><\/em> has the &#8220;<em><strong>===&#8221;<\/strong><\/em> operator to check for equality. What is the difference between these two operators?<\/p>\n<p>The <em><strong>&#8220;==&#8221;<\/strong><\/em> operator checks whether two objects have the same <span style=\"text-decoration: underline;\"><em><strong>value<\/strong><\/em><\/span>. Here are some examples:<\/p>\n<figure id=\"attachment_3172\" aria-describedby=\"caption-attachment-3172\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"3172\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/07\/23\/the-operator-in-julia\/examples1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg\" data-orig-size=\"485,953\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1690103177&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The &amp;#8220;==&amp;#8221; Operator\" data-image-description=\"&lt;p&gt;The &amp;#8220;==&amp;#8221; Operator&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The &amp;#8220;==&amp;#8221; Operator&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg\" class=\"wp-image-3172\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg?resize=350%2C688&#038;ssl=1\" alt=\"The &quot;==&quot; Operator\" width=\"350\" height=\"688\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg?resize=153%2C300&amp;ssl=1 153w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples1.jpg?w=485&amp;ssl=1 485w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-3172\" class=\"wp-caption-text\"><strong>The &#8220;==&#8221; Operator<\/strong><\/figcaption><\/figure>\n<p><strong>Cell 5<\/strong> shows that the RHS <em><strong>float<\/strong><\/em> value is converted to <em><strong>int<\/strong><\/em> before checking for equality. <strong>Cell 8<\/strong> shows that Julia handles <em><strong>NaN<\/strong><\/em> as a special value.<\/p>\n<p>The &#8220;<em><strong>===&#8221;<\/strong><\/em> operator is stricter than <em><strong>&#8220;==&#8221;<\/strong><\/em>. It checks whether the two operands are <span style=\"text-decoration: underline;\"><em><strong>bitwise<\/strong><\/em><\/span> equal. Here are some examples:<\/p>\n<figure id=\"attachment_3173\" aria-describedby=\"caption-attachment-3173\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3173\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/07\/23\/the-operator-in-julia\/examples2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg\" data-orig-size=\"463,547\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1690119833&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The &amp;#8220;===&amp;#8221; Operator\" data-image-description=\"&lt;p&gt;The &amp;#8220;===&amp;#8221; Operator&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The &amp;#8220;===&amp;#8221; Operator&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg\" class=\"wp-image-3173\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg?resize=350%2C413&#038;ssl=1\" alt=\"The &quot;===&quot; Operator\" width=\"350\" height=\"413\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg?resize=254%2C300&amp;ssl=1 254w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples2.jpg?w=463&amp;ssl=1 463w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-3173\" class=\"wp-caption-text\"><strong>The &#8220;===&#8221; Operator<\/strong><\/figcaption><\/figure>\n<p>Look at <strong>Cells 11<\/strong> and <strong>13<\/strong>. The behavior is different from that of <em><strong>&#8220;==&#8221;<\/strong><\/em> operator.<\/p>\n<p><em><strong>Common Lisp<\/strong><\/em> has<em><strong> &#8220;=&#8221;<\/strong><\/em>, <em><strong>\u201ceq\u201d<\/strong><\/em>, <em><strong>\u201ceql\u201d<\/strong><\/em>, <em><strong>\u201cequal\u201d<\/strong><\/em>, and <em><strong>\u201cequalp\u201d<\/strong><\/em> for comparing two objects and is the only language that I know with such finer distinctions. Please see this <a href=\"https:\/\/eli.thegreenplace.net\/2004\/08\/08\/equality-in-lisp\" target=\"_blank\" rel=\"noopener\"><em><strong>article<\/strong><\/em><\/a>\u00a0 for more details.<\/p>\n<p>Other languages that have the <em><strong>&#8220;===&#8221;<\/strong><\/em> operator are <em><strong>PHP<\/strong><\/em> and <em><strong>Javascript<\/strong><\/em>. <em><strong>Ruby<\/strong><\/em> also has this operator but its semantics is different.<\/p>\n<p>Finally, <em><strong>Julia<\/strong><\/em> also has <em><strong>\u201cisequal()\u201d<\/strong><\/em> function to compare two objects.<\/p>\n<figure id=\"attachment_3174\" aria-describedby=\"caption-attachment-3174\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3174\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/07\/23\/the-operator-in-julia\/examples3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg\" data-orig-size=\"515,422\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1690121836&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"isequal() Function\" data-image-description=\"&lt;p&gt;isequal() Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;isequal() Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg\" class=\"wp-image-3174\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg?resize=350%2C287&#038;ssl=1\" alt=\"isequal() Function\" width=\"350\" height=\"287\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg?resize=300%2C246&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/07\/examples3.jpg?w=515&amp;ssl=1 515w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-3174\" class=\"wp-caption-text\"><strong>isequal() Function<\/strong><\/figcaption><\/figure>\n<p>You can see that <strong>Cell 29<\/strong> is similar to <em><strong>&#8220;==&#8221;<\/strong><\/em> operator and <strong>Cell 30<\/strong> behaves like <em><strong>&#8220;===&#8221;<\/strong><\/em> operator.<\/p>\n<p>It is clear from the above examples that the choice of <em><strong>&#8220;==&#8221;<\/strong><\/em>, <em><strong>&#8220;===&#8221;<\/strong><\/em> and <em><strong>\u201cisequal\u201d<\/strong><\/em> is dictated by the usage context.<\/p>\n<p>Have a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In addition to the conventional &#8220;==&#8221; operator that checks if two objects are equal, Julia has the &#8220;===&#8221; operator to check for equality. What is the difference between these two operators? The &#8220;==&#8221; operator checks whether two objects have the same value. Here are some examples: Cell 5 shows that the RHS float value is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[63,17],"tags":[365,366,64],"class_list":["post-3171","post","type-post","status-publish","format-standard","hentry","category-julia","category-programming","tag-comparing-objects","tag-equality","tag-julia"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-P9","jetpack-related-posts":[{"id":3035,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/05\/julia-defining-functions-dynamically\/","url_meta":{"origin":3171,"position":0},"title":"Julia: Defining Functions Dynamically","author":"admin","date":"March 5, 2023","format":false,"excerpt":"One of the widely discussed features of Julia is its support for metaprogramming. This feature makes it possible to generate and inspect the code at runtime. In essence, metaprogramming blurs the distinction between code and data. When used carefully, it can contribute to good code. Of course, Julia is not\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"Defining A Function Dynamically","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Example1-300x195.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Example1-300x195.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Example1-300x195.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2947,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/11\/24\/using-julia-from-mathematica\/","url_meta":{"origin":3171,"position":1},"title":"Using Julia from Mathematica","author":"admin","date":"November 24, 2022","format":false,"excerpt":"In an earlier article, I had shown how it is possible to interact with Mathematica from Julia. In today\u2019s article, I will share the details of how to interact with Julia from within Mathematica. Why would somebody want to execute Julia code inside Mathematica? Although Mathematica is a great symbolic\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"Installing Julia","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/11\/Julia-Shell.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3017,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/02\/16\/calling-external-dll-functions-from-julia\/","url_meta":{"origin":3171,"position":2},"title":"Calling External DLL Functions from Julia","author":"admin","date":"February 16, 2023","format":false,"excerpt":"Julia supports calling external functions, especially those written in \u201cC\u201d language. As Julia documentation says, such calls do not involve any \u201cboilerplate\u201d code and hence are efficient. In today\u2019s article, I am going to show how to call functions defined in a DLL (Windows 64 bit). Instead of using direct\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"The \"lispEval\" Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/02\/code-300x117.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":293,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/08\/07\/is-deriving-from-a-concrete-class-bad\/","url_meta":{"origin":3171,"position":3},"title":"Is Deriving from a Concrete Class Bad?","author":"admin","date":"August 7, 2016","format":false,"excerpt":"In my first post on Julia, I noted that the language does not allow deriving from a concrete (i.e., non-abstract) class. It definitely came as a surprise because in most OO languages (C++, Java, Scala, C#, etc.) such a restriction does not exist. It is true that when you design\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2084,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/08\/16\/pattern-matching-comparing-elixir-and-mathematica\/","url_meta":{"origin":3171,"position":4},"title":"Pattern Matching: Comparing Elixir and Mathematica","author":"admin","date":"August 16, 2020","format":false,"excerpt":"One of the things I like about Elixir\u00a0is its support for patterns at the core language level, not through library functions as in most other languages. This contributes to writing cleaner code, in my opinion. \u00a0 Another environment that I am familiar with, namely Mathematica, boasts of (arguably) the most\u2026","rel":"","context":"In &quot;Elixir&quot;","block_context":{"text":"Elixir","link":"https:\/\/www.rangakrish.com\/index.php\/category\/elixir\/"},"img":{"alt_text":"Symbolic Expressions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/08\/pattern-mm.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1981,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/09\/dynamic_cast-vs-stdis_base_of\/","url_meta":{"origin":3171,"position":5},"title":"dynamic_cast vs. std::is_base_of","author":"admin","date":"May 9, 2020","format":false,"excerpt":"In the last article, we looked at the std:is_base_of<T1, T2> type trait. One question that a reader asked since that article appeared is \"How does is_base_of<> differ from the dynamic_cast<> operator?\" Good question! In today's post let me try to address the key differences between the two. I am not\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Case-4: Complex Hierarchy","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=3171"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=3171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=3171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=3171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}