Difference between revisions of "Equal"

From Free Pascal wiki
Jump to navigationJump to search
(rename →‎example: to →‎application: ; mention handling with IEEE 754 formats)
(substitute legacy syntaxhighlight syntax, mention enumeration data type [indices], unify source code style)
 
Line 2: Line 2:
 
<div style="float:right; margin: 0 10px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">=</div>
 
<div style="float:right; margin: 0 10px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">=</div>
  
The symbol <syntaxhighlight lang="pascal" enclose="none">=</syntaxhighlight> (pronounced “equal”) is used to
+
The symbol <syntaxhighlight lang="pascal" inline>=</syntaxhighlight> (pronounced “equal”) is used to
 
* compare two (comparable) values for equality,
 
* compare two (comparable) values for equality,
* [[Constant|constant]] declarations (including [[Resourcestring|<syntaxhighlight lang="pascal" enclose="none">resourcestring</syntaxhighlight> sections]]), and
+
* [[Constant|constant]] declarations (including [[Resourcestring|<syntaxhighlight lang="pascal" inline>resourcestring</syntaxhighlight> sections]]), and
 
* [[Type|type declarations]], as well as
 
* [[Type|type declarations]], as well as
 
* specifying [[Default parameter|default values]] for formal parameters in method declarations.
 
* specifying [[Default parameter|default values]] for formal parameters in method declarations.
 +
Furthermore, if [[Enum Type|enumeration data types]] are defined with explicit indices, [[FPC]]’s Delphi compatibility modes require an equal sign instead of [[Becomes|<syntaxhighlight lang="pascal" inline>:=</syntaxhighlight>]] when specifying the indices.
  
 
== application ==
 
== application ==
Line 35: Line 36:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Be aware of ''what'' you compare:
 
Be aware of ''what'' you compare:
When you compare two references, i.e. [[Class|<syntaxhighlight lang="pascal" enclose="none">class</syntaxhighlight>]] or [[Pointer|<syntaxhighlight lang="pascal" enclose="none">pointer</syntaxhighlight>]] variables, without dereferencing them first, you usually compare two memory addresses, ''not'' the actual content at those addresses.
+
When you compare two references, i.e. [[Class|<syntaxhighlight lang="pascal" inline>class</syntaxhighlight>]] or [[Pointer|<syntaxhighlight lang="pascal" inline>pointer</syntaxhighlight>]] variables, without dereferencing them first, you usually compare two memory addresses, ''not'' the actual content at those addresses.
 
Operator overloading may alter this behavior, though.
 
Operator overloading may alter this behavior, though.
For instance the content of [[Ansistring|<syntaxhighlight lang="pascal" enclose="none">ansistring</syntaxhighlight>s]] can be compared without any special treatment, though ''internally'' (transparently) they are realized as pointers.
+
For instance the content of [[Ansistring|<syntaxhighlight lang="pascal" inline>ansistring</syntaxhighlight>s]] can be compared without any special treatment, though ''internally'' (transparently) they are realized as pointers.
  
 
Note, you usually do not use the equal sign comparison in conjunction with [[IEEE 754 formats|floating-point numbers]].
 
Note, you usually do not use the equal sign comparison in conjunction with [[IEEE 754 formats|floating-point numbers]].
Instead one uses {{Doc|package=RTL|unit=math|identifier=comparevalue|text=<syntaxhighlight lang="pascal" enclose="none">math.compareValue</syntaxhighlight>}}.
+
Instead one uses {{Doc|package=RTL|unit=math|identifier=comparevalue|text=<syntaxhighlight lang="pascal" inline>math.compareValue</syntaxhighlight>}}.
  
 
== comparitive remarks ==
 
== comparitive remarks ==
Unlike other programming languages, the symbol is ''not'' used to assign a value, for that the character pair [[Becomes|<syntaxhighlight lang="pascal" enclose="none">:=</syntaxhighlight>]] is used.
+
Unlike other programming languages, the symbol is ''not'' used to assign a value, for that the character pair [[Becomes|<syntaxhighlight lang="pascal" inline>:=</syntaxhighlight>]] is used.
An exception of this are “initialized variables”, where you specify an initial value inside the [[Var|<syntaxhighlight lang="pascal" enclose="none">var</syntaxhighlight> section]] alongside your [[Variable|variable]] declarations:
+
An exception of this are “initialized variables”, where you specify an initial value inside the [[Var|<syntaxhighlight lang="pascal" inline>var</syntaxhighlight> section]] alongside your [[Variable|variable]] declarations:
 
<syntaxhighlight lang="pascal" highlight="5">
 
<syntaxhighlight lang="pascal" highlight="5">
 
program initializedVariable(input, output, stderr);
 
program initializedVariable(input, output, stderr);
Line 65: Line 66:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Also, a comparison ''always'' results in a [[Boolean|<syntaxhighlight lang="pascal" enclose="none">boolean</syntaxhighlight> value]].
+
Also, a comparison ''always'' results in a [[Boolean|<syntaxhighlight lang="pascal" inline>boolean</syntaxhighlight> value]].
  
 
== ASCII value ==
 
== ASCII value ==
 
+
In [[ASCII]], the character code decimal <syntaxhighlight lang="pascal" inline>61</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" inline>3D</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" inline>=</syntaxhighlight> (equals sign).
In [[ASCII]], the character code decimal <syntaxhighlight lang="pascal" enclose="none">61</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" enclose="none">3D</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">=</syntaxhighlight> (equals sign).
 
  
 
== see also ==
 
== see also ==
* [[Becomes|becomes-operator <syntaxhighlight lang="pascal" enclose="none">:=</syntaxhighlight>]] assigns values to a variable
+
* [[Becomes|becomes-operator <syntaxhighlight lang="pascal" inline>:=</syntaxhighlight>]] assigns values to a variable
* [[Not equal|not-equal-operator <syntaxhighlight lang="pascal" enclose="none"><></syntaxhighlight>]] checks for inequality
+
* [[Not equal|not-equal-operator <syntaxhighlight lang="pascal" inline><></syntaxhighlight>]] checks for inequality
  
 
{{Symbols}}
 
{{Symbols}}

Latest revision as of 14:03, 10 November 2020

English (en) suomi (fi) français (fr) русский (ru)

=

The symbol = (pronounced “equal”) is used to

Furthermore, if enumeration data types are defined with explicit indices, FPC’s Delphi compatibility modes require an equal sign instead of := when specifying the indices.

application

program equalDemo(input, output, stderr);

const
	answer = 42;

resourcestring
	prompt = 'What''s the answer?';

type
	number = longint;

var
	i: number;

begin
	writeLn(prompt);
	readLn(i);
	
	if not (i = answer) then
	begin
		exitCode := 1;
	end;
end.

Be aware of what you compare: When you compare two references, i.e. class or pointer variables, without dereferencing them first, you usually compare two memory addresses, not the actual content at those addresses. Operator overloading may alter this behavior, though. For instance the content of ansistrings can be compared without any special treatment, though internally (transparently) they are realized as pointers.

Note, you usually do not use the equal sign comparison in conjunction with floating-point numbers. Instead one uses math.compareValue.

comparitive remarks

Unlike other programming languages, the symbol is not used to assign a value, for that the character pair := is used. An exception of this are “initialized variables”, where you specify an initial value inside the var section alongside your variable declarations:

program initializedVariable(input, output, stderr);

var
	i: longint;
	response: string = 'Wrong!';

begin
	writeLn('What''s the answer?');
	readLn(i);
	
	if i = 42 then
	begin
		response := 'Right!';
	end;
	
	writeLn(response);
end.

Also, a comparison always results in a boolean value.

ASCII value

In ASCII, the character code decimal 61 (or hexadecimal 3D) is defined to be = (equals sign).

see also


navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)