Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Equals sign
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Usage in mathematics and computer programming== In mathematics, the equals sign can be used as a simple statement of fact in a specific case ("{{nowrap|''x'' {{=}} 2}}"), or to create definitions ("{{nowrap|let ''x'' {{=}} 2}}"), conditional statements ("{{nowrap|if ''x'' {{=}} 2, then ...}}"), or to express a universal equivalence ("{{nowrap|(''x'' + 1)<sup>2</sup> {{=}} ''x''<sup>2</sup> + 2''x'' + 1}}"). The first important [[computer programming language]] to use the equals sign was the original version of [[Fortran]], FORTRAN I, designed in 1954 and implemented in 1957. In Fortran, {{char|1==}} serves as an [[assignment (computer science)|assignment]] operator: {{nowrap|{{code|1=X = 2}}}} sets the value of {{code|X}} to 2. This somewhat resembles the use of {{char|1==}} in a mathematical definition, but with different semantics: the expression following {{char|1==}} is evaluated first, and may refer to a previous value of {{code|X}}. For example, the assignment {{nowrap|{{code|1=X = X + 2}}}} increases the value of {{code|X}} by 2. A rival programming-language usage was pioneered by the original version of [[ALGOL]], which was designed in 1958 and implemented in 1960. ALGOL included a [[relational operator]] that tested for equality, allowing constructions like {{nowrap|{{code|1=if x = 2}}}} with essentially the same meaning of {{char|1==}} as the conditional usage in mathematics. The equals sign was reserved for this usage. Both usages have remained common in different programming languages into the early-21st century. As well as Fortran, {{char|1==}} is used for assignment in such languages as [[C (programming language)|C]], [[Perl]], [[Python (programming language)|Python]], [[awk|AWK]] and their descendants. But {{char|1==}} is used for equality and not assignment in the [[Pascal (programming language)|Pascal]] family, [[Ada (programming language)|Ada]], [[Eiffel (programming language)|Eiffel]], [[APL (programming language)|APL]], and other languages. A few languages, such as [[BASIC]] and [[PL/I]], have used the equals sign to mean both assignment and equality, distinguished by context. However, in most languages where {{char|1==}} has one of these meanings, a different character or, more often, a sequence of characters is used for the other meaning. Following ALGOL, most languages that use {{char|1==}} for equality use {{char|1=:=}} for assignment, although APL, with its special character set, uses a left-pointing arrow. Fortran did not have an equality operator (it was only possible to compare an expression to zero, using the [[arithmetic IF]] statement) until FORTRAN{{nbsp}}IV was released in 1962, since when it has used the four characters {{code|.EQ.}} to test for equality. The language [[B (programming language)|B]] introduced the use of {{char|1===}} with this meaning, which has been copied by its descendant C and most later languages where {{char|1==}} means assignment. Some languages additionally feature the "[[spaceship operator]]", or three-way comparison operator, {{char|1=<=>}}, to determine whether one value is less than, equal to, or greater than another. ===Several equals signs=== In some programming languages, <code>==</code> and <code>===</code> are used to check equality, so <code>1844 == 1844</code> will return true. In [[PHP]], the [[===|triple equals sign]], {{code|1====}}, denotes value and [[Data type|type]] equality,<ref>{{cite web | url = https://www.php.net/manual/en/language.operators.comparison.php | title = Comparison Operators | website = [[Php.net]] | access-date = 19 October 2013 | archive-date = 19 October 2013 | archive-url = https://web.archive.org/web/20131019192727/http://php.net/manual/en/language.operators.comparison.php | url-status = live }}</ref> meaning that not only do the two expressions evaluate to equal values, but they are also of the same data type. For instance, the expression {{nowrap|{{code|1=0 == false}}}} is true, but {{nowrap|{{code|1=0 === false}}}} is not, because the number 0 is an integer value whereas false is a Boolean value. [[JavaScript]] has the same semantics for {{code|1====}}, referred to as "equality without type coercion". However, in JavaScript the behavior of {{code|1===}} cannot be described by any simple consistent rules. The expression {{nowrap|{{code|1=0 == false}}}} is true, but {{nowrap|{{code|1=0 == undefined}}}} is false, even though both sides of the {{code|1===}} act the same in Boolean context. For this reason it is sometimes recommended to avoid the {{code|1===}} operator in JavaScript in favor of {{code|1====}}.<ref>{{cite web |last = Crockford |first = Doug |title = JavaScript: The Good Parts |website = [[YouTube]] |date = 27 February 2009 |url = https://www.youtube.com/watch?v=hQVTIJBZook |access-date = 19 October 2013 |archive-date = 4 November 2013 |archive-url = https://web.archive.org/web/20131104115604/http://www.youtube.com/watch?v=hQVTIJBZook |url-status = live }}</ref> In Ruby, equality under {{code|1===}} requires both operands to be of identical type, e.g. {{nowrap|{{code|1=0 == false}}}} is false. The {{code|1====}} operator is flexible and may be defined arbitrarily for any given type. For example, a value of type {{code|Range}} is a range of integers, such as {{code|1800..1899}}. {{nowrap|{{code|1=(1800..1899) == 1844}}}} is false, since the types are different (Range vs. Integer); however {{nowrap|{{code|1=(1800..1899) === 1844}}}} is true, since {{code|1====}} on {{code|Range}} values means "inclusion in the range".<ref>{{cite book |title = [[why's (poignant) Guide to Ruby]] |chapter = 5.1 This One's For the Disenfranchised |author = why the lucky stiff |author-link = why the lucky stiff |chapter-url = http://mislav.uniqpath.com/poignant-guide/book/chapter-5.html#section1 |access-date = 19 October 2013 |archive-date = 24 September 2015 |archive-url = https://web.archive.org/web/20150924063735/http://mislav.uniqpath.com/poignant-guide/book/chapter-5.html#section1 |url-status = dead }}</ref> Under these semantics, <code>===</code> is [[Symmetric relation|non-symmetric]]; e.g. <code>1844 === (1800..1899)</code> is false, since it is interpreted to mean <code>Integer#===</code> rather than <code>Range#===</code>.<ref>{{cite web |last = Rasmussen |first = Brett |title = Don't Call it Case Equality |date = 30 July 2009 |url = http://www.pmamediagroup.com/2009/07/dont-call-it-case-equality/ |website = pmamediagroup.com |access-date = 19 October 2013 |archive-url = https://web.archive.org/web/20131021062941/http://www.pmamediagroup.com/2009/07/dont-call-it-case-equality/ |archive-date = 21 October 2013 }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)