Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating and Double types range in java

Tags:

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?

like image 903
Hairi Avatar asked May 02 '26 12:05

Hairi


2 Answers

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
like image 90
Misha Avatar answered May 05 '26 03:05

Misha


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

like image 40
Thirumal Avatar answered May 05 '26 02:05

Thirumal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!