Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code of my previous question

 
rashid khokhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
link with long==>float
class myclass{
float i;//float have 32 bits.
long j;//long have 64 bits.
void method(){
j=2043223;
i=j;// convert long into float
System.out.println(i);
}
}
class tester{
public static void main(String agrs[]){
myclass my=new myclass();
my.method();
}
}
output = 2043223.0

------------------
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rashid,
quoting Rana Thakur:
Rana Thakur
greenhorn posted February 27, 2001 08:14 AM
--------------------------------------------------------------------------------
Hi,
The value for a long variable will be stored as 64 bits.
However the floating point value will be stored in 32 bits in IEEE floating point format.i.e left most bit for sign bit, next 7 bits from the left for exponent and the remaining 24 bits for mantissa. Thus the value that can be stored using this format(maximum value being 3.4E+038) is much higher than that of the value that can be stored in a simple long variable(max value (2^63)-1). Hence the conversion is widening and not narrowing.

------------------------------------------------------
There was some discussion about this point in the forum. Search for "float".
A float can take up a higher value then a long. The cost is lower precicion.
hope this helps
Axel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic