Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:40 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Arithmetic Promotion
PostPosted: Fri Jan 30, 2009 1:46 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Arithmetic Promotion :
This topic talk about Arithmetic promotion in Java.Suppose you have an arithmetic on two variables with different types.Here come what is called "Arithmetic promotion". In this case the compiler will convert the data type of one operand in the binary arithmetic operation to the type of the other.

Here is the rules of arithmetic promotion in Java language :

- One operand is of type "double" , then the other operand is promoted to the type double.
- Both operands are of type less than "int" , for example (byte,short,char...) .Both operands are promoted to type integer.
- if one of operands is type float and the other is not double .The other operand is converted to type float.
- if one of operands is type long and the other is not double or float .The other operand is converted to type long.
- if no operand of type (double,float ,long ) , then convert to type integer .

Note : All arithmetic promotion is done before calculations .

The result return type will be the common type created after the arithmetic promotion.

Note :
Any arithmetic operations will be at least of type integer (int) .

For example :
Code:
byte a=2;
byte b=4;

the result of a*b or a/b will be of type integer .


Last thing you must take in mind that you can't convert any type , there will be a situations you will need to use the cast operator <type> of java.

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Web Promotion Mistakes
 Program for "Selection of arithmetic operations" in Java
 Arithmetic Operators in java
 Arithmetic data comparison in C#

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 5 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team