EXPRESSIONS
Logical Complement Operator
!
15.14.6
15.14.4 Unary Minus Operator
The type of the operand expression of the unary
operator must be a primitive
numeric type, or a compile time error occurs. Unary numeric promotion ( 5.6.1)
is performed on the operand. The type of the unary minus expression is the pro
moted type of the operand.
At run time, the value of the unary plus expression is the arithmetic negation
of the promoted value of the operand.
For integer values, negation is the same as subtraction from zero. Java uses
two's complement representation for integers, and the range of two's complement
values is not symmetric, so negation of the maximum negative
int
or
long
results
in that same maximum negative number. Overflow occurs in this case, but no
exception is thrown. For all integer values
x
,
x
equals
(~x)+1
.
For floating point values, negation is not the same as subtraction from zero,
because if
x
is
+0.0
, then
0.0 x
equals
+0.0
, but
x
equals
0.0
. Unary minus
merely inverts the sign of a floating point number. Special cases of interest:
If the operand is NaN, the result is NaN (recall that NaN has no sign).
If the operand is an infinity, the result is the infinity of opposite sign.
If the operand is a zero, the result is the zero of opposite sign.
15.14.5 Bitwise Complement Operator
~
The type of the operand expression of the unary
~
operator must be a primitive
integral type, or a compile time error occurs. Unary numeric promotion ( 5.6.1) is
performed on the operand. The type of the unary bitwise complement expression
is the promoted type of the operand.
At run time, the value of the unary bitwise complement expression is the bit
wise complement of the promoted value of the operand; note that, in all cases,
~x
equals
( x) 1
.
15.14.6 Logical Complement Operator
!
The type of the operand expression of the unary
!
operator must be
boolean,
or a
compile time error occurs. The type of the unary logical complement expression
is
boolean
.
At run time, the value of the unary logical complement expression is
true
if
the operand value is
false
and
false
if the operand value is
true
.
349
footer
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