Download presentation
Presentation is loading. Please wait.
Published byRosanna McCoy Modified over 9 years ago
1
BATCH:- 2011 BRANCH:- CSE 2 ND SEM
2
SUBMITTED BY:- GINNI
3
TITLE :- RELATIONAL OPERATORS
4
INTRODUCTION In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (e.g., 5 = 5) and inequalities (e.g., 4 ≥ 3). In programming languages that include a distinct boolean data type in their type system, like Java, these operators return true or false, depending on whether the conditional relationship between the two operands holds or not. In other languages such as C, relational operators return the integers 0 1.
5
An expression created using a relational operator forms what is known as a relational expression or a condition. Relational operators are also used in technical literature instead of words. Relational operators are usually written in infix notation, if supported by the programming language, which means that they appear between their operands (the two expressions being related). For example, an expression in C will print the message if the x is less than y: if (x < y) { printf("x is less than y in this example\n"); }
6
COMMON RELATIONAL OPERATORS onventionequal tonot equal togreater than less thangreater than or equal toless than or equal to In print=≠><≥≤ ALGOL 68 [note 1]=≠><≥ ≤ /=>=<= eqnegtltgele C-like[note 2]==!=><>= <= BASIC-like[note 3]=<>><>= <= Mathematica[1]==!=><>= <= Equal[x,y]Unequal[x,y]Greater[x,y] Less[x,y]GreaterEqual[x,y]LessEqual[x,y] MATLAB[note 4]==~=><>= <= eq(x,y)ne(x,y)gt(x,y)lt(x,y)ge(x,y)le(x,y) ortran [note 5]==/=><>=F <=.
7
Confusion with assignment operators, Oberon, Dylan, VHDL, and several other languageEarly FORTRAN (1956–57) was bounded by heavily restricted character sets where "=" was the only relational operator available. There were no " " (and certainly no ≤ or ≥). This forced the designers to define symbols such as.GT.,.LT.,.GE.,.EQ. etc. and subsequently made it tempting to use the remaining "=" character for copying, despite the obvious incoherence with mathematical usage (X=X+1 should be impossible). International Algebraic Language and ALGOL (1958 and 1960) therefore introduced ":=" for assignment, leaving the standard "=" available for equality, a convention followed by CPL, Algol W, BCPL, Simula, Algol 68, SETL, Pascal, Smalltalk, Modula2, Ada, Standard ML, Objective Caml, Eiffel, Delphis.
8
The relational operators compare two arithmetic objects. Obviously, the two should be of same type. In case the objects that are compared are not of same type, the less complex object is converted to a more complex object before comparison. So, when comparing an integer or a real number with a complex number, the integer or the real number is converted to a complex number. Further, a meaningful comparison can only b done with scalar objects. The relational operators in fortran 77 and fortran 90 and their meaning is shown in the accompanying table.
9
LOGICAL TREE
11
Relational model Data items organized as a set of formally described tables from which data can be accessed or reassembled in many ways without having to reorganize the database tables. Each table (sometimes called a relation) contains one or more data categories in columns. Each row contains a unique instance of data for the categories defined by the columns.
12
There are six relational operators: < : less than <= : less than or equal to > : greater than >= : greater than or equal to == : equal to /= : not equal to Types of relational operators:-
13
Here are important rules:- EEach of these six relational operators takes two operands. These two operands must both be arithmetic or both be strings. For arithmetic operands, if they are of different types (i.e., one INTEGER and the other REAL), the INTEGER operand will be converted to REAL. TThe outcome of a comparison is a LOGICAL value. For example, 5 /= 3 is.TRUE. and 7 + 3 >= 20 is.FALSE.
14
All relational operators have equal priority and are lower than those of arithmetics operators as shown in the table below: Type Operator Associativity Arithmetic ** right to left * / left to right + - left to right Relational >= == /= none This means that a relational operator can be evaluated only if its two operands have been evaluated. For example, in a + b /= c*c + d*d expressions a+b and c*c + d*d are evaluated before the relational operator /= is evaluated.
15
If you are not comfortable in writing long relational expressions, use parenthesis. Thus, 3.0*SQRT(Total)/(Account + Sum) - Sum*Sum >= Total*GNP - b*b is equivalent to the following: (3.0*SQRT(Total)/(Account + Sum) - Sum*Sum) >= (Total*GNP - b*b) Although a < b < c is legal in mathematics, you cannot write comparisons this way in Fortran. The meaning of this expression is a < b and b < c. You should use logical operator to achieve this.
16
Examples 3**2 + 4**2 == 5**2 is.TRUE. If the values of REAL variables a, b and c are 1.0, 2.0 and 4.0, respectively, then b*b - 4.0*a*c >= 0.0 is equivalent to 2.0*2.0 - 4.0*1.0*4.0 >= 0.0, which evaluates to -12.0 >= 0.0. Thus, the result is.FALSE. If REAL variables x and y have values 3.0 and 7.0, and INTEGER variables p and q have values 6 and 2, what is the result of x*x - y*y + 2.0*x*y /= p*q + p**3 - q**3?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.