Standard relational operators

Standard relational operators

The standard numerical relational operators used in programming languages are shown below.

Common relational operators
In programming languages In print Meaning Used to:
C-like 1 BASIC-like 2 Mathematica[1] MATLAB 3 Fortran 4 Bourne-like shells 5 MUMPS
== = == Equal[x,y] == eq(x,y) == .EQ. -eq = = equal to Test the equivalence of two values.
!= <> != Unequal[x,y] ~= ne(x,y) /= .NE. -ne '= not equal to Test the negated equivalence of two values.
> > > Greater[x,y] > gt(x,y) > .GT. -gt > > greater than Test if the value of the left expression is greater than that of the right.
< < < Less[x,y] < lt(x,y) < .LT. -lt < < less than Test if the value of the left expression is less than that of the right.
>= >= >= GreaterEqual[x,y] >= ge(x,y) >= .GE. -ge '< greater than or equal to Test if the value of the left expression is greater than or equal to that of the right.
<= <= <= LessEqual[x,y] <= le(x,y) <= .LE. -le '> less than or equal to Test if the value of the left expression is less than or equal to that of the right.
Note (1): Including C, C++, C#, Go, Java, JavaScript, Perl (numerical comparison only), PHP, Python, and Ruby.
Note (2): Including BASIC, Visual Basic .NET, VB.NET, Objective Caml, Pascal, SQL, and Standard ML.
Note (3): MATLAB, although in other respects using similar syntax as C, does not use !=, as ! in MATLAB sends the following text as a command line to the operating system.
Note (4): The first form including Haskell.
Note (5): Including Bourne shell, Bash, Korn shell, and Windows PowerShell. The symbols < and > are usually used in a shell for redirection, so other symbols need to be used. Without the hyphen, is used in Perl for string comparison.



The following table lists the different mechanisms to test for these two types of equality in various languages:

Language Physical equality Structural equality Notes
C, C++ a == b *a == *b a and b are pointers
C# object.ReferenceEquals(a, b)1 a.Equals(b)1
Common Lisp (eq a b) (equal a b)
Java a == b a.equals(b) a and b are references
Objective Caml a == b a = b
Pascal a^ = b^ a = b
Perl $a == $b $$a == $$b $a and $b are references to scalars
PHP5 N/A $a == $b $a and $b are objects
Python a is b a == b
Ruby a.equal?(b) a == b
Scheme (eq? a b) (equal? a b)
Visual Basic .NET a Is b a = b
Objective-C a == b [a isEqual:b] a and b are pointers to objects

1 In C#, the == operator defaults to ReferenceEquals, but can be overloaded to perform Equals instead. This allows to test for structural equality wherever it's more intuitive, most notably in string comparison.


크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 홍반장

2011/03/15 16:30 2011/03/15 16:30
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/5934

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/5934

« Previous : 1 : ... 533 : 534 : 535 : 536 : 537 : 538 : 539 : 540 : 541 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/11   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Statistics Graph

Site Stats

Total hits:
240382
Today:
178
Yesterday:
856