Hairi
Hairi

Reputation: 3725

Floating and Double types range in java

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?

Upvotes: 3

Views: 5241

Answers (3)

Misha
Misha

Reputation: 28133

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

Upvotes: 2

Thirumal
Thirumal

Reputation: 9536

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

Upvotes: 2

Priyamal
Priyamal

Reputation: 2969

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

Upvotes: 1

Related Questions