File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes primitive types Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

primitive types

Arun Prasath
Ranch Hand

Joined: Jul 18, 2006
Posts: 60
code:
-----

long x=1;
float f=x;

How is long variable 'x' assigned to float variable 'f' ,since long is holiding 8 bytes and float is only 4 bytes?
Lanny Gilbert
Ranch Hand

Joined: Jun 11, 2002
Posts: 103
Methinks someone is studying for the SCJP, no???

anyway, this ought to help...

long
8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807.


float
4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).

Like all numeric types floats may be cast into other numeric types (byte, short, long, int, double). When lossy casts to integer types are done (e.g. float to short) the fractional part is truncated and the conversion is done modulo the length of the smaller type.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24040
    
  13

Moving to Java in General (Beginner).


[Jess in Action][AskingGoodQuestions]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: primitive types
 
Similar Threads
about interface
how it is possible??????
primitive types assignment
Why is this implicit cast legal?
primitive types