Constants in Double class

TypeFieldSummary
static intMAX_EXPONENTMaximum exponent a finite double variable may have.
static doubleMAX_VALUELargest positive finite value of type double.
static intMIN_EXPONENTMinimum exponent a normalized double variable may have.
static doubleMIN_NORMALSmallest positive normal value of type double.
static doubleMIN_VALUESmallest positive nonzero value of type double.
static doubleNaNNot-a-Number (NaN) value of type double.
static doubleNEGATIVE_INFINITYNegative infinity of type double.
static doublePOSITIVE_INFINITYPositive infinity of type double.
static intSIZEThe number of bits used to represent a double value.
static ClassTYPEThe Class instance representing the primitive type double.

The following code finds out the min/max value a double type variable can have. It also prints out the size of a double value.


public class Main {
  public static void main(String[] args) {
    System.out.println(Double.MAX_VALUE);
    System.out.println(Double.MIN_VALUE);
    System.out.println(Double.SIZE);

  }
}

The output:


1.7976931348623157E308
4.9E-324
64

public class Main {
  public static void main(String[] args) {
    System.out.println(Double.MAX_EXPONENT);
    System.out.println(Double.MIN_EXPONENT);
    System.out.println(Double.MIN_NORMAL);

  }
}

The output:


1023
-1022
2.2250738585072014E-308
The following code uses the Double.NEGATIVE_INFINITY to check a double value.

public class Main {
  public static void main(String args[]) {

    double d = -10.0 / 0.0;
    if (d == Double.NEGATIVE_INFINITY) {
      System.out.println("d = " + d);
    }

  }
}
The output:

d = -Infinity
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.