aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Primitive test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Primitive test" Watch "Primitive test" New topic
Author

Primitive test

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Hi,
Can any one please let me know why compile time error is not generated when a long is assigned to a float ? Float is of size 32 bits but long is of size 64 bits.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Annette Sovereign
Greenhorn

Joined: Jul 12, 2005
Posts: 26
Hi there,

This is to do with primitive widening conversion (google-whack it).

You only lose precision (i.e. lose significant bits) and in Java, that's acceptable.


Hope this helps.

AO


-- just trying to get one foot on the ladder
Santana Iyer
Ranch Hand

Joined: Jun 13, 2005
Posts: 335
float is 32 bits and long is 64 bits but
storage mechanism is not same

try
System.out.print(Float.MAX_VALUE);
System.out.print(Long.MAX_VALUE);

or

float f=Long.MAX_VALUE;
System.out.println(f); // exponent is 18
System.out.println(Float.MAX_VALUE); // exponent is 38

float uses IEEE754 storage mechanism hence can store number larger in magnitude than long.

word magnitude is more important.
hope this helps and correct me if I am wrong
bye.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Primitive test