Underflow of DataTypes in Java

Object Oriented ProgrammingProgrammingJava 8

Underflow occurs when the given value is less than the maximum prescribed size of a data type. The underflow condition can result to an error or now the implementation of the programming language handles it on its own.

To display underflow of datatypes, I have taken an example of double datatype. Double data type is a single-precision 64-bit IEEE 754 floating point.

The following program display underflow of datatype in Java.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      System.out.println("Displaying Underflow... ");
      double val1 = 3.2187E-320;
      System.out.println(val1/1000000);
   }
}

Output

Displaying Underflow...
0.0

In the above program, the double variable is initialized to.

double val1 = 3.2187E-320;

After that, division operation is performed on it to check for underflow.

val1/1000000

It returns the following.

0.0
raja
Published on 13-Nov-2018 07:37:18
Advertisements