EXPRESSIONS
Numerical Equality Operators
==
and
!=
15.20.1
EqualityExpression:
RelationalExpression
EqualityExpression
 ==
RelationalExpression
EqualityExpression
 !=
RelationalExpression
The == (equal to) and the != (not equal to) operators are analogous to the rela 
tional operators except for their lower precedence. Thus,
a
 is
true
 when 
ever
a
 and
c
 have the same truth value.
The equality operators may be used to compare two operands of numeric
type, or two operands of type
boolean
, or two operands that are each of either ref 
erence type or the null type. All other cases result in a compile time error. The
type of an equality expression is always
boolean
.
In all cases,
a!=b
 produces the same result as
!(a==b)
. The equality opera 
tors are commutative if the operand expressions have no side effects.
15.20.1   Numerical Equality Operators
==
and
!=
If the operands of an equality operator are both of primitive numeric type, binary
numeric promotion is performed on the operands ( 5.6.2). If the promoted type of
the operands is
int
 or
long
, then an integer equality test is performed; if the pro 
moted type is
float
 or
double
, then a floating point equality test is performed.
Floating point equality testing is performed in accordance with the rules of
the IEEE 754 standard:
If either operand is NaN, then the result of
==
 is
false
 but the result of
!=
 is
true
. Indeed, the test
x!=x
 is true if and only if the value of
x
 is NaN. (The
methods
Float.isNaN
 ( 20.9.19) and
Double.isNaN
 ( 20.10.17) may also
be used to test whether a value is NaN.)
Positive zero and negative zero are considered equal. Therefore,
 0.0==0.0
 is
true
, for example.
Otherwise, two distinct floating point values are considered unequal by the
equality operators. In particular, there is one value representing positive infin 
ity and one value representing negative infinity; each compares equal only to
itself, and each compares unequal to all other values.
Subject to these considerations for floating point numbers, the following rules
then hold for integer operands or for floating point operands other than NaN:
363






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved