Java Language Java Floating Point Operations OverFlow and UnderFlow

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Float data type

The float data type is a single-precision 32-bit IEEE 754 floating point.

Float overflow

Maximum possible value is 3.4028235e+38 , When it exceeds this value it produces Infinity

float f = 3.4e38f;
float result = f*2;        
System.out.println(result); //Infinity

Float UnderFlow

Minimum value is 1.4e-45f, when is goes below this value it produces 0.0

    float f = 1e-45f;
    float result = f/1000;
    System.out.println(result);

double data type

The double data type is a double-precision 64-bit IEEE 754 floating point.

Double OverFlow

Maximum possible value is 1.7976931348623157e+308 , When it exceeds this value it produces Infinity

double d = 1e308;
double result=d*2;      
System.out.println(result); //Infinity

Double UnderFlow

Minimum value is 4.9e-324, when is goes below this value it produces 0.0

    double d = 4.8e-323;
    double result = d/1000;
    System.out.println(result); //0.0


Got any Java Language Question?