tags:

views:

192

answers:

4

Can any one tell what is numeric promotion?

+10  A: 

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

Warrior
+3  A: 

http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.6

You could really just have googled that...

sleske
A: 

If you look here, you will see the following quote:

Numeric promotion (§5.6) brings the operands of a numeric operator to a common type so that an operation can be performed.

They are referencing this section, where they give a variety of examples. The classic example is that of an int times a float. The integer is promoted to a float so that the multiplied result is, therefore, a float.

Bob Cross
A: 

Numeric promotion is a conversion of an operand (at least one of the numbers involved) to a common type.

For example:

int i = 10;
double d1 = 2.5;
double d2 = d1 * i;

In this case, i is promoted to double so the calculation can be performed. In some ways, you can think of this is analogous to boxing, but boxing involves moving from a struct to an object (from the stack to the heap). But, using the analogy does give an idea of the fact the integral value is being made into a floating point to perform the calculation.

Gregory A Beamer