Package java.lang

Class Double

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double INF_EXPONENT  
      static double MAX_VALUE
      A constant holding the largest positive finite value of type double, (2-2-52)·21023.
      static double MIN_VALUE
      A constant holding the smallest positive nonzero value of type double, 2-1074.
      static double MIN_VALUE_NORM
      A constant holding the smallest positive normalized value of type double, 2-1074.
      static double NaN
      A constant holding a Not-a-Number (NaN) value of type double.
      static double NEGATIVE_INFINITY
      A constant holding the negative infinity of type double.
      static double POSITIVE_INFINITY
      A constant holding the positive infinity of type double.
      static int SIZE
      The number of bits used to represent a Double value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Double​(double value)
      Constructs a newly allocated Double object that represents the primitive double argument.
      Double​(String string)
      Constructs a new Double from the specified string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte byteValue()
      Returns this object's value as a byte.
      static int compare​(double double1, double double2)
      Compares the two specified double values.
      int compareTo​(Double object)
      Compares this object to the specified double object to determine their relative order.
      static int doubleToChars​(double val, int nofFractDigits, char[] chars)  
      double doubleValue()
      Returns the double value of this Double object.
      boolean equals​(Object object)
      Tests this double for equality with object.
      float floatValue()
      Returns this object's value as a float.
      static int getExponent​(double arg)
      Returns the exponent of a double precision value to the base of 2.
      int hashCode()
      Returns an integer hash code for this object.
      static int highPartToIntBits​(double arg)
      Returns an integer corresponding to the upper 32 bits of the given IEEE 754 double precision value.
      int intValue()
      Returns this object's value as an int.
      boolean isInfinite()
      Indicates whether this object represents an infinite value.
      static boolean isInfinite​(double d)
      Indicates whether the specified double represents an infinite value.
      boolean isNaN()
      Indicates whether this object is a Not-a-Number (NaN) value.
      static boolean isNaN​(double d)
      Indicates whether the specified double is a Not-a-Number (NaN) value.
      long longValue()
      Returns this object's value as a long.
      static int lowPartToIntBits​(double arg)
      Returns an integer corresponding to the lower 32 bits of the given IEEE 754 double precision value.
      static double parseDouble​(String s)
      Returns the closest double value to the real number in the string.
      static double powOf10​(int e)
      Calculates power to the base of 10
      static double setExponent​(double d, int newExp)
      Sets the exponent of a double precision value to the base of 2 and returns the new value.
      short shortValue()
      Returns this object's value as a short.
      String toString()
      Returns a string containing a concise, human-readable description of this object.
      static String toString​(double d)
      Returns a string containing a concise, human-readable description of the specified double value.
      static Double valueOf​(double d)
      Returns a Double instance for the specified double value.
      static Double valueOf​(String string)
      Parses the specified string as a double value.
    • Field Detail

      • POSITIVE_INFINITY

        public static final double POSITIVE_INFINITY
        A constant holding the positive infinity of type double. It is equal to the value returned by Double.longBitsToDouble(0x7ff0000000000000L).
        See Also:
        Constant Field Values
      • NEGATIVE_INFINITY

        public static final double NEGATIVE_INFINITY
        A constant holding the negative infinity of type double. It is equal to the value returned by Double.longBitsToDouble(0xfff0000000000000L).
        See Also:
        Constant Field Values
      • NaN

        public static final double NaN
        A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L).
        See Also:
        Constant Field Values
      • MAX_VALUE

        public static final double MAX_VALUE
        A constant holding the largest positive finite value of type double, (2-2-52)·21023. It is equal to the hexadecimal floating-point literal 0x1.fffffffffffffP+1023 and also equal to Double.longBitsToDouble(0x7fefffffffffffffL).
        See Also:
        Constant Field Values
      • MIN_VALUE

        public static final double MIN_VALUE
        A constant holding the smallest positive nonzero value of type double, 2-1074. It is equal to the hexadecimal floating-point literal 0x0.0000000000001P-1022 and also equal to Double.longBitsToDouble(0x1L).
        See Also:
        Constant Field Values
      • MIN_VALUE_NORM

        public static final double MIN_VALUE_NORM
        A constant holding the smallest positive normalized value of type double, 2-1074. It is equal to the hexadecimal floating-point literal Double.longBitsToDouble(1L << 52).
        See Also:
        Constant Field Values
      • SIZE

        public static final int SIZE
        The number of bits used to represent a Double value.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Double

        public Double​(double value)
        Constructs a newly allocated Double object that represents the primitive double argument.
        Parameters:
        value - the value to be represented by the Double.
    • Method Detail

      • powOf10

        public static double powOf10​(int e)
        Calculates power to the base of 10
        Parameters:
        e - this is the exponent
        Returns:
        power of 10e.
      • highPartToIntBits

        public static int highPartToIntBits​(double arg)
        Returns an integer corresponding to the upper 32 bits of the given IEEE 754 double precision value.
        Parameters:
        arg - Double argument.
        Returns:
        Upper 32 bits.
      • lowPartToIntBits

        public static int lowPartToIntBits​(double arg)
        Returns an integer corresponding to the lower 32 bits of the given IEEE 754 double precision value.
        Parameters:
        arg - Double argument.
        Returns:
        Lower 32 bits.
      • getExponent

        public static int getExponent​(double arg)
        Returns the exponent of a double precision value to the base of 2.
        Parameters:
        arg - Double argument.
        Returns:
        Exponent.
      • setExponent

        public static double setExponent​(double d,
                                         int newExp)
        Sets the exponent of a double precision value to the base of 2 and returns the new value.
        Parameters:
        d - Double
        newExp - New exponent.
        Returns:
        New double value.
      • doubleToChars

        public static int doubleToChars​(double val,
                                        int nofFractDigits,
                                        char[] chars)
      • valueOf

        public static Double valueOf​(double d)
        Returns a Double instance for the specified double value.
        Parameters:
        d - the double value to store in the instance.
        Returns:
        a Double instance containing d.
        Since:
        1.5
      • valueOf

        public static Double valueOf​(String string)
                              throws NumberFormatException
        Parses the specified string as a double value.
        Parameters:
        string - the string representation of a double value.
        Returns:
        a Double instance containing the double value represented by string.
        Throws:
        NumberFormatException - if string cannot be parsed as a double value.
        See Also:
        parseDouble(String)
      • parseDouble

        public static double parseDouble​(String s)
                                  throws NumberFormatException
        Returns the closest double value to the real number in the string.
        Parameters:
        s - the String that will be parsed to a floating point
        Returns:
        the double closest to the real number
        Throws:
        NumberFormatException - if the String doesn't represent a double
      • doubleValue

        public double doubleValue()
        Returns the double value of this Double object.
        Specified by:
        doubleValue in class Number
        Returns:
        the double value represented by this object
      • byteValue

        public byte byteValue()
        Description copied from class: Number
        Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.
        Overrides:
        byteValue in class Number
        Returns:
        the primitive byte value of this object.
      • floatValue

        public float floatValue()
        Description copied from class: Number
        Returns this object's value as a float. Might involve rounding.
        Specified by:
        floatValue in class Number
        Returns:
        the primitive float value of this object.
      • intValue

        public int intValue()
        Description copied from class: Number
        Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.
        Specified by:
        intValue in class Number
        Returns:
        the primitive int value of this object.
      • longValue

        public long longValue()
        Description copied from class: Number
        Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.
        Specified by:
        longValue in class Number
        Returns:
        the primitive long value of this object.
      • shortValue

        public short shortValue()
        Description copied from class: Number
        Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.
        Overrides:
        shortValue in class Number
        Returns:
        the primitive short value of this object.
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

        Note that hash values must not change over time unless information used in equals comparisons also changes.

        See Writing a correct hashCode method if you intend implementing your own hashCode method.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • toString

        public static String toString​(double d)
        Returns a string containing a concise, human-readable description of the specified double value.
        Parameters:
        d - the double to convert to a string.
        Returns:
        a printable representation of d.
      • compareTo

        public int compareTo​(Double object)
        Compares this object to the specified double object to determine their relative order. There are two special cases:
        • Double.NaN is equal to Double.NaN and it is greater than any other double value, including Double.POSITIVE_INFINITY;
        • +0.0d is greater than -0.0d
        Specified by:
        compareTo in interface Comparable<Double>
        Parameters:
        object - the double object to compare this object to.
        Returns:
        a negative value if the value of this double is less than the value of object; 0 if the value of this double and the value of object are equal; a positive value if the value of this double is greater than the value of object.
        Throws:
        NullPointerException - if object is null.
        Since:
        1.2
        See Also:
        Comparable
      • compare

        public static int compare​(double double1,
                                  double double2)
        Compares the two specified double values. There are two special cases:
        • Double.NaN is equal to Double.NaN and it is greater than any other double value, including Double.POSITIVE_INFINITY;
        • +0.0d is greater than -0.0d
        Parameters:
        double1 - the first value to compare.
        double2 - the second value to compare.
        Returns:
        a negative value if double1 is less than double2; 0 if double1 and double2 are equal; a positive value if double1 is greater than double2.
      • equals

        public boolean equals​(Object object)
        Tests this double for equality with object. To be equal, object must be an instance of Double and doubleToLongBits must give the same value for both objects.

        Note that, unlike ==, -0.0 and +0.0 compare unequal, and NaNs compare equal by this method.

        Overrides:
        equals in class Object
        Parameters:
        object - the object to compare this double with.
        Returns:
        true if the specified object is equal to this Double; false otherwise.
        See Also:
        Object.hashCode()
      • isInfinite

        public boolean isInfinite()
        Indicates whether this object represents an infinite value.
        Returns:
        true if the value of this double is positive or negative infinity; false otherwise.
      • isInfinite

        public static boolean isInfinite​(double d)
        Indicates whether the specified double represents an infinite value.
        Parameters:
        d - the double to check.
        Returns:
        true if the value of d is positive or negative infinity; false otherwise.
      • isNaN

        public boolean isNaN()
        Indicates whether this object is a Not-a-Number (NaN) value.
        Returns:
        true if this double is Not-a-Number; false if it is a (potentially infinite) double number.
      • isNaN

        public static boolean isNaN​(double d)
        Indicates whether the specified double is a Not-a-Number (NaN) value.
        Parameters:
        d - the double value to check.
        Returns:
        true if d is Not-a-Number; false if it is a (potentially infinite) double number.