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

Double and Float size

 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just came across this
float g = 456666666.45454354
//compiler error loss of precision
May i know what is the maximum size that a float and double can store ?
We are not expected to memorize the size of double and float aren't we ? Saw many books stated "not necessary"
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
float: 32 byte
double: 64 byte
so:
-10^16 <= float <= 10^16 - 1
-10^32 <= float <= 10^32 - 1
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May i know what is the maximum size that a float and double can store ?


You may find the constants MAX_VALUE and MIN_VALUE helpful while studying. They are defined in each of the wrapper classes Byte, Short, Integer, Long, Float, Double and Character, but not Boolean.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//compiler error loss of precision

: possible loss of precision
found : double
required: float
float g = 456666666.45454354;
1 error
This error is misleading. The real problem is a number of type double is being assigned to a variable of type float.
 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marlene

the example is taken from K&B book, you are right about it. It is a float value that was assigned to a double value.
 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Temp
>java MaxValue
float max = 3.4028235E38
double max = 1.7976931348623157E308
character max = ?
interger max = 2147483647
long max = 9223372036854775807
short max = 32767
byte max = 127
May I know why character max = ?
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just realized i made a mistake, thanks for the example, it really clear things up!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic