5.6.2
Binary Numeric Promotion
CONVERSIONS AND PROMOTIONS
5.6.2   Binary Numeric Promotion
When an operator applies
binary numeric promotion
 to a pair of operands, each of
which must denote a value of a numeric type, the following rules apply, in order,
using widening conversion ( 5.1.2) to convert operands as necessary:
If either operand is of type
double
, the other is converted to
double
.
Otherwise, if either operand is of type
float
, the other is converted to
float
.
Otherwise, if either operand is of type
long
, the other is converted to
long
.
Otherwise, both operands are converted to type
int
.
Binary numeric promotion is performed on the operands of certain operators:
The multiplicative operators
*
,
/
 and
%
 ( 15.16)
The addition and subtraction operators for numeric types
+
 and
( 15.17.2)
The numerical comparison operators
<
,
<=
,
>
, and
>=
 ( 15.19.1)
The numerical equality operators
==
 and
!=
 ( 15.20.1)
The integer bitwise operators
&
,
^
, and
|
 ( 15.21.1)
In certain cases, the conditional operator
? :
 ( 15.24)
An example of binary numeric promotion appears above in  5.1. Here is another:
class Test {
public static void main(String[] args) {
int i = 0;
float f = 1.0f;
double d = 2.0;
//
First
i*f
 promoted to
float*float
, then
// float==double
 is promoted to
double==double
:
if (i * f == d)
System.out.println("oops");
//
A
char&byte
 is promoted to
int&int
:
byte b = 0x1f;
char c =  G ;
int control = c & b;
System.out.println(Integer.toHexString(control));
//
A
int:float
 promoted to
float:float
:
f = (b==0) ? f : 4.0f;
System.out.println(1.0/f);
}
}
74






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