• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

float and double range

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found th maximum value for float as 3.402e38 in JLS.But according to solutions for mock exams the value 314e7 and 42e7 cannot be assigned to a float type variable, why is that?

What's the range for float and double types in scientific notation?

Please reply soon..i have the exam tommorrow.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not because of the range of 314e7 and 42e7 is outside float rather their sizes are 64 bit. That's why you can't assign it in float.

For example following is legal.



Here is a quote from JLS 3.0

The largest positive finite float literal is 3.4028235e38f. The smallest positive finite nonzero literal of type float is 1.40e-45f. The largest positive finite double literal is 1.7976931348623157e308. The smallest positive finite nonzero literal of type double is 4.9e-324.



All the best for your exams

Naseem
 
Saumya Tangeda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are the values 314e7 and 42e7, not in int range i.e less than the maximum value for int type - 2147483647?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question is not that whether they are in the range of int or not. 3e1 is definitely in the range of int but still you can't assign it in int. Reason is simple, 3e1 is a double can't be assigned to int.

So you have to cast it in int.

By the way these ranges are not required in exam. Just you need to know ranges of char and integral data types. Nothing more.



Above five ranges are not difficult to remember. Integral types are from...

-2^(bit-1) to 2^(bit-1)-1


Nothing else is required in ranges.


Naseem
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic