3

I am beginner in Java and I am just reading one of the pdfs for beginners like me. So in my book I found this:

enter image description here

So for example the floating point numbers may be within the range of

1.4E-45 to 3.4028235E+38

So according to my math, that number can be very small (near the zero) or quite large, but it CAN NOT be a negative number.

Am I correct?

Hairi
  • 3,318
  • 2
  • 29
  • 68
  • That PDF is wrong for `float`, `double` and `boolean`. [What is the size of a boolean variable in Java?](http://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java). Also `float` and `double` are both floating point and can both be negative. – Jonny Henly Apr 24 '16 at 08:14
  • Mhmm this is a reference to it: http://www.ebooksbucket.com/uploads/itprogramming/java/Java_in_a_Nutshell_6th_Edition.pdf – Hairi Apr 24 '16 at 08:18
  • Being pedantic, the default value for `long` is `0L` and the default for `float` is `0.0f`, and `boolean` uses 1 byte and a field or in an array of them. – Peter Lawrey Apr 24 '16 at 09:04

3 Answers3

2

Float range is approximately ±3.40282347E+38F (6-7 significant decimal digits) Java implements IEEE 754 standard.

Refer below links

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

http://cs-fundamentals.com/java-programming/java-primitive-data-types.php

Thirumal
  • 8,280
  • 11
  • 53
  • 103
2

The book states the MIN_VALUE and MAX_VALUE for the floating point types. This range describes available precision but it is certainly not the case that all values must fall between MIN_VALUE and MAX_VALUE as you can easily confirm by assigning zero or a negative number to a float variable.

Floating point values (float and double) can be one of the following:

  • NaN (not a number)
  • negative infinity
  • a negative number between -MAX_VALUE and -MIN_VALUE
  • negative zero
  • positive zero
  • a positive number between MIN_VALUE and MAX_VALUE
  • positive infinity
Misha
  • 27,433
  • 6
  • 62
  • 78
1

here you are considering the minimimum value of float . minimum value of float (MIN_VALUE) prints the most accurate float it can get, but not the mathematical minimum it can represent.

integers can hold negative values and integers can be cast to float later. think about that.

range of float : 32 bits -3.4E+38 to +3.4E+38

Priyamal
  • 2,919
  • 2
  • 25
  • 52