Search code examples
javadoubleprecision

Is there a way that double d + 1 == d in java


I'm just curious if there's a way that d + 1 == d. If d is a double. Maybe someone can share some knowledge with me.


Solution

  • Yes, certainly.

    class Main {  
      public static void main(String args[]) { 
        System.out.println(1.0e52 + 1); 
      } 
    }
    

    prints

    1.0E52

    This will actually be true for numbers with absolute value at least 253, because the mantissa of a double has 52 bits of precision.