• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java primitive casting

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first question
what is the min and max value for double and float and how will i get it i mean calculation? (please make it simple as much as possible)
second question
i know about assigning a integer literal value that is too large for the variable (higher order bits are cut off) my question is how will that work for decimal literal. if i assign a number that is too big for float we have to cast it to double . then what will be the result ??
 
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can get max and min values of primitive types by using wrapper classes. They are java.lang package.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fahmida tasnim prema wrote:first question
what is the min and max value for double and float and how will i get it i mean calculation? (please make it simple as much as possible)


Mark Spencers wrote:You can get max and min values of primitive types by using wrapper classes. They are java.lang package.



Some little notes to remember. The Double.MAX_VALUE variable does specify the largest possible value, but the Double.MIN_VALUE does not hold the largest negative number (like it's Integer counterpart).  The largest possible negative value is actually (-1 * Double.MAX_VALUE).

Additionally, floats and doubles support Infinity and Negative Infinity, so arguably, Double.MAX_VALUE and (-1 * Double.MAX_VALUE) are the maximum/minimum before it becomes infinity / negative infinity.

And as for Double.MIN_VALUE, that is the smallest possible positive number. This is the smallest possible number that is greater than zero -- and trying to make it smaller (while keeping it positive) will make it positive zero.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fahmida tasnim prema wrote:
i know about assigning a integer literal value that is too large for the variable (higher order bits are cut off) my question is how will that work for decimal literal. if i assign a number that is too big for float we have to cast it to double . then what will be the result ??



The rules for floating point are defined by the IEEE 754 standard. And quite frankly, it is somewhat complicated.

Keep in mind that as a float variable get nears Float.MAX_VALUE, there is a ridiculous loss of precision, so, it is very difficult to get pass Float.MAX_VALUE. If you are going to do it via a double, then, I guess, the float result will either be Float.MAX_VALUE or Infinity depending on how it is defined by the specification (meaning what is the double value, the precision loss, and the rounding that happens during the conversion).

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic