Back to index

plt-scheme  4.2.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Package Functions | Static Package Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes
java.lang.Double Class Reference

Instances of class Double represent primitive double values. More...

Inheritance diagram for java.lang.Double:
Inheritance graph
[legend]
Collaboration diagram for java.lang.Double:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Double (double value)
 Load native routines necessary for this class.
 Double (String s)
 Create a Double from the specified String.
boolean isNaN ()
 Return true if the value of this Double is the same as NaN, otherwise return false.
boolean isInfinite ()
 Return true if the value of this Double is the same as NEGATIVE_INFINITY or POSITIVE_INFINITY, otherwise return false.
String toString ()
 Convert the double value of this Double to a String.
byte byteValue ()
 Return the value of this Double as a byte.
short shortValue ()
 Return the value of this Double as a short.
int intValue ()
 Return the value of this Double as an int.
long longValue ()
 Return the value of this Double as a long.
float floatValue ()
 Return the value of this Double as a float.
double doubleValue ()
 Return the value of this Double.
int hashCode ()
 Return a hashcode representing this Object.
boolean equals (Object obj)
 Returns true if obj is an instance of Double and represents the same double value.
int compareTo (Double d)
 Compare two Doubles numerically by comparing their double values.
int compareTo (Object o)
 Behaves like compareTo(Double) unless the Object is not an Double.

Static Public Member Functions

static String toString (double d)
 Convert the double to a String.
static Double valueOf (String s)
 Create a new Double object using the String.
static double parseDouble (String str)
static boolean isNaN (double v)
 Return true if the double has the same value as NaN, otherwise return false.
static boolean isInfinite (double v)
 Return true if the double has a value equal to either NEGATIVE_INFINITY or POSITIVE_INFINITY, otherwise return false.
static native long doubleToLongBits (double value)
 Convert the double to the IEEE 754 floating-point "double format" bit layout.
static native long doubleToRawLongBits (double value)
 Convert the double to the IEEE 754 floating-point "double format" bit layout.
static native double longBitsToDouble (long bits)
 Convert the argument in IEEE 754 floating-point "double format" bit layout to the corresponding float.
static int compare (double x, double y)
 Behaves like new Double(x).compareTo(new Double(y)); in other words this compares two doubles, special casing NaN and zero, without the overhead of objects.

Static Public Attributes

static final double MAX_VALUE = 1.7976931348623157e+308
 The maximum positive value a double may represent is 1.7976931348623157e+308.
static final double MIN_VALUE = 5e-324
 The minimum positive value a double may represent is 5e-324.
static final double NEGATIVE_INFINITY = getNegInf()
 The value of a double representation -1.0/0.0, negative infinity.
static final double POSITIVE_INFINITY = getPosInf()
 The value of a double representing 1.0/0.0, positive infinity.
static final double NaN = getNaN()
 All IEEE 754 values of NaN have the same value in Java.

Static Package Functions

static native double parseDoubleHelper (String str)
 Parse the specified String as a double.
static native String toString (double d, boolean isFloat)
 Helper method to convert to string.

Static Package Attributes

static final char[] digits
 Table for calculating digits, used in Character, Long, and Integer.

Static Private Member Functions

static native double getNegInf ()
static native double getPosInf ()
static native double getNaN ()
static native void initIDs ()
 Initialize JNI cache.

Private Attributes

final double value
 The primitive type double is represented by this Class object.

Static Private Attributes

static final long serialVersionUID = -9172774392245257468L
 Compatible with JDK 1.0+.

Detailed Description

Instances of class Double represent primitive double values.

Additionally, this class provides various helper functions and variables related to doubles.

Author:
Paul Fisher
Andrew Haley aph@c.nosp@m.ygnu.nosp@m.s.com
Eric Blake ebb9@.nosp@m.emai.nosp@m.l.byu.nosp@m..edu
Since:
1.0 updated to 1.4

Definition at line 56 of file Double.java.


Constructor & Destructor Documentation

java.lang.Double.Double ( double  value) [inline]

Load native routines necessary for this class.

Create a Double from the primitive double specified.

Parameters:
valuethe double argument

Definition at line 127 of file Double.java.

  {
    this.value = value;
  }

Here is the caller graph for this function:

java.lang.Double.Double ( String  s) [inline]

Create a Double from the specified String.

This method calls Double.parseDouble().

Parameters:
sthe String to convert
Exceptions:
NumberFormatExceptionif s cannot be parsed as a double
NullPointerExceptionif s is null
See also:
parseDouble(String)

Definition at line 142 of file Double.java.

  {
    value = parseDouble(s);
  }

Here is the call graph for this function:


Member Function Documentation

Return the value of this Double as a byte.

Returns:
the byte value
Since:
1.1

Reimplemented from java.lang.Number.

Definition at line 332 of file Double.java.

  {
    return (byte) value;
  }
static int java.lang.Double.compare ( double  x,
double  y 
) [inline, static]

Behaves like new Double(x).compareTo(new Double(y)); in other words this compares two doubles, special casing NaN and zero, without the overhead of objects.

Parameters:
xthe first double to compare
ythe second double to compare
Returns:
the comparison
Since:
1.4

Definition at line 531 of file Double.java.

  {
    if (isNaN(x))
      return isNaN(y) ? 0 : 1;
    if (isNaN(y))
      return -1;
    // recall that 0.0 == -0.0, so we convert to infinites and try again
    if (x == 0 && y == 0)
      return (int) (1 / x - 1 / y);
    if (x == y)
      return 0;

    return x > y ? 1 : -1;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Compare two Doubles numerically by comparing their double values.

The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal. However, this special cases NaN and signed zero as follows: NaN is considered greater than all other doubles, including POSITIVE_INFINITY, and positive zero is considered greater than negative zero.

Parameters:
dthe Double to compare
Returns:
the comparison
Since:
1.2

Definition at line 500 of file Double.java.

  {
    return compare(value, d.value);
  }

Here is the call graph for this function:

int java.lang.Double.compareTo ( Object  o) [inline]

Behaves like compareTo(Double) unless the Object is not an Double.

Parameters:
othe object to compare
Returns:
the comparison
Exceptions:
ClassCastExceptionif the argument is not a Double
See also:
compareTo(Double)
Comparable
Since:
1.2

Definition at line 516 of file Double.java.

  {
    return compare(value, ((Double) o).value);
  }

Here is the call graph for this function:

static native long java.lang.Double.doubleToLongBits ( double  value) [static]

Convert the double to the IEEE 754 floating-point "double format" bit layout.

Bit 63 (the most significant) is the sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa. This function collapses all versions of NaN to 0x7ff8000000000000L. The result of this function can be used as the argument to Double.longBitsToDouble(long) to obtain the original double value.

Parameters:
valuethe double to convert
Returns:
the bits of the double
See also:
longBitsToDouble(long)

Here is the caller graph for this function:

static native long java.lang.Double.doubleToRawLongBits ( double  value) [static]

Convert the double to the IEEE 754 floating-point "double format" bit layout.

Bit 63 (the most significant) is the sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa. This function leaves NaN alone, rather than collapsing to a canonical value. The result of this function can be used as the argument to Double.longBitsToDouble(long) to obtain the original double value.

Parameters:
valuethe double to convert
Returns:
the bits of the double
See also:
longBitsToDouble(long)
double java.lang.Double.doubleValue ( ) [inline, virtual]

Return the value of this Double.

Returns:
the double value

Implements java.lang.Number.

Definition at line 383 of file Double.java.

  {
    return value;
  }
boolean java.lang.Double.equals ( Object  obj) [inline]

Returns true if obj is an instance of Double and represents the same double value.

Unlike comparing two doubles with ==, this treats two instances of Double.NaN as equal, but treats 0.0 and -0.0 as unequal.

Note that d1.equals(d2) is identical to doubleToLongBits(d1.doubleValue()) == doubleToLongBits(d2.doubleValue()).

Parameters:
objthe object to compare
Returns:
whether the objects are semantically equal

Definition at line 417 of file Double.java.

  {
    if (! (obj instanceof Double))
      return false;

    double d = ((Double) obj).value;

    // Avoid call to native method. However, some implementations, like gcj,
    // are better off using floatToIntBits(value) == floatToIntBits(f).
    // Check common case first, then check NaN and 0.
    if (value == d)
      return (value != 0) || (1 / value == 1 / d);
    return isNaN(value) && isNaN(d);
  }

Here is the call graph for this function:

float java.lang.Double.floatValue ( ) [inline, virtual]

Return the value of this Double as a float.

Returns:
the float value

Implements java.lang.Number.

Definition at line 373 of file Double.java.

  {
    return (float) value;
  }
static native double java.lang.Double.getNaN ( ) [static, private]
static native double java.lang.Double.getNegInf ( ) [static, private]
static native double java.lang.Double.getPosInf ( ) [static, private]

Return a hashcode representing this Object.

Double's hash code is calculated by:
long v = Double.doubleToLongBits(doubleValue());
int hash = (int)(v^(v>>32))
.

Returns:
this Object's hash code
See also:
doubleToLongBits(double)

Definition at line 397 of file Double.java.

  {
    long v = doubleToLongBits(value);
    return (int) (v ^ (v >>> 32));
  }

Here is the call graph for this function:

static native void java.lang.Double.initIDs ( ) [static, private]

Initialize JNI cache.

This method is called only by the static initializer when using JNI.

int java.lang.Double.intValue ( ) [inline, virtual]

Return the value of this Double as an int.

Returns:
the int value

Implements java.lang.Number.

Definition at line 353 of file Double.java.

  {
    return (int) value;
  }
static boolean java.lang.Double.isInfinite ( double  v) [inline, static]

Return true if the double has a value equal to either NEGATIVE_INFINITY or POSITIVE_INFINITY, otherwise return false.

Parameters:
vthe double to compare
Returns:
whether the argument is (-/+) infinity.

Definition at line 285 of file Double.java.

  {
    return v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY;
  }

Return true if the value of this Double is the same as NEGATIVE_INFINITY or POSITIVE_INFINITY, otherwise return false.

Returns:
whether this Double is (-/+) infinity

Definition at line 308 of file Double.java.

  {
    return isInfinite(value);
  }
static boolean java.lang.Double.isNaN ( double  v) [inline, static]

Return true if the double has the same value as NaN, otherwise return false.

Parameters:
vthe double to compare
Returns:
whether the argument is NaN.

Definition at line 270 of file Double.java.

  {
    // This works since NaN != NaN is the only reflexive inequality
    // comparison which returns true.
    return v != v;
  }

Return true if the value of this Double is the same as NaN, otherwise return false.

Returns:
whether this Double is NaN

Definition at line 296 of file Double.java.

  {
    return isNaN(value);
  }

Here is the caller graph for this function:

static native double java.lang.Double.longBitsToDouble ( long  bits) [static]

Convert the argument in IEEE 754 floating-point "double format" bit layout to the corresponding float.

Bit 63 (the most significant) is the sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa. This function leaves NaN alone, so that you can recover the bit pattern with Double.doubleToRawLongBits(double).

Parameters:
bitsthe bits to convert
Returns:
the double represented by the bits
See also:
doubleToLongBits(double)
doubleToRawLongBits(double)
long java.lang.Double.longValue ( ) [inline, virtual]

Return the value of this Double as a long.

Returns:
the long value

Implements java.lang.Number.

Definition at line 363 of file Double.java.

  {
    return (long) value;
  }
static double java.lang.Double.parseDouble ( String  str) [inline, static]

Definition at line 252 of file Double.java.

                                               {
    if (null == str) 
      throw new NullPointerException("parseDouble expected to receive String, received null value");      
    try {
      return parseDoubleHelper(str);
      }
    catch (RuntimeException e) {
      throw new NumberFormatException(e.getMessage());
      }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static native double java.lang.Double.parseDoubleHelper ( String  str) [static, package]

Parse the specified String as a double.

The extended BNF grammar is as follows:

 DecodableString:
      ( [ - | + ] NaN )
    | ( [ - | + ] Infinity )
    | ( [ - | + ] FloatingPoint
              [ f | F | d
                | D] )
 FloatingPoint:
      ( { Digit }+ [ . { Digit } ]
              [ Exponent ] )
    | ( . { Digit }+ [ Exponent ] )
 Exponent:
      ( ( e | E )
              [ - | + ] { Digit }+ )
 Digit: '0' through '9'
 

NaN and infinity are special cases, to allow parsing of the output of toString. Otherwise, the result is determined by calculating n * 10exponent to infinite precision, then rounding to the nearest double. Remember that many numbers cannot be precisely represented in floating point. In case of overflow, infinity is used, and in case of underflow, signed zero is used. Unlike Integer.parseInt, this does not accept Unicode digits outside the ASCII range.

If an unexpected character is found in the String, a NumberFormatException will be thrown. Leading and trailing 'whitespace' is ignored via String.trim(), but spaces internal to the actual number are not allowed.

To parse numbers according to another format, consider using java.text.NumberFormat.

specify where/how we are not in accord with the spec.

Parameters:
strthe String to convert
Returns:
the double value of s
Exceptions:
NumberFormatExceptionif s cannot be parsed as a double
NullPointerExceptionif s is null
See also:
MIN_VALUE
MAX_VALUE
POSITIVE_INFINITY
NEGATIVE_INFINITY
Since:
1.2

Here is the caller graph for this function:

short java.lang.Double.shortValue ( ) [inline]

Return the value of this Double as a short.

Returns:
the short value
Since:
1.1

Reimplemented from java.lang.Number.

Definition at line 343 of file Double.java.

  {
    return (short) value;
  }
static String java.lang.Double.toString ( double  d) [inline, static]

Convert the double to a String.

Floating-point string representation is fairly complex: here is a rundown of the possible values. "<code>[-]</code>" indicates that a negative sign will be printed if the value (or exponent) is negative. "<code>&lt;number&gt;</code>" means a string of digits ('0' to '9'). "<code>&lt;digit&gt;</code>" means a single digit ('0' to '9').

Value of DoubleString Representation
[+-] 0 [-]0.0
Between [+-] 10-3 and 107, exclusive [-]number.number
Other numeric value [-]<digit>.<number> E[-]<number>
[+-] infinity [-]Infinity
NaN NaN

Yes, negative zero is a possible value. Note that there is always a . and at least one digit printed after it: even if the number is 3, it will be printed as 3.0. After the ".", all digits will be printed except trailing zeros. The result is rounded to the shortest decimal number which will parse back to the same double.

To create other output formats, use java.text.NumberFormat.

specify where we are not in accord with the spec.

Parameters:
dthe double to convert
Returns:
the String representing the double

Definition at line 181 of file Double.java.

  {
    return toString(d, false);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

String java.lang.Double.toString ( ) [inline]

Convert the double value of this Double to a String.

This method calls Double.toString(double) to do its dirty work.

Returns:
the String representation
See also:
toString(double)

Definition at line 321 of file Double.java.

  {
    return toString(value);
  }

Here is the caller graph for this function:

static native String java.lang.Double.toString ( double  d,
boolean  isFloat 
) [static, package]

Helper method to convert to string.

Parameters:
dthe double to convert
isFloattrue if the conversion is requested by Float (results in fewer digits)
static Double java.lang.Double.valueOf ( String  s) [inline, static]

Create a new Double object using the String.

Parameters:
sthe String to convert
Returns:
the new Double
Exceptions:
NumberFormatExceptionif s cannot be parsed as a double
NullPointerExceptionif s is null.
See also:
parseDouble(String)

Definition at line 196 of file Double.java.

  {
    return new Double(parseDouble(s));
  }

Here is the call graph for this function:


Member Data Documentation

final char [] java.lang.Number.digits [static, package, inherited]
Initial value:
 {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z',
  }

Table for calculating digits, used in Character, Long, and Integer.

Definition at line 68 of file Number.java.

final double java.lang.Double.MAX_VALUE = 1.7976931348623157e+308 [static]

The maximum positive value a double may represent is 1.7976931348623157e+308.

Definition at line 67 of file Double.java.

final double java.lang.Double.MIN_VALUE = 5e-324 [static]

The minimum positive value a double may represent is 5e-324.

Definition at line 73 of file Double.java.

final double java.lang.Double.NaN = getNaN() [static]

All IEEE 754 values of NaN have the same value in Java.

Definition at line 89 of file Double.java.

final double java.lang.Double.NEGATIVE_INFINITY = getNegInf() [static]

The value of a double representation -1.0/0.0, negative infinity.

Definition at line 79 of file Double.java.

final double java.lang.Double.POSITIVE_INFINITY = getPosInf() [static]

The value of a double representing 1.0/0.0, positive infinity.

Definition at line 84 of file Double.java.

final long java.lang.Double.serialVersionUID = -9172774392245257468L [static, private]

Compatible with JDK 1.0+.

Reimplemented from java.lang.Number.

Definition at line 61 of file Double.java.

final double java.lang.Double.value [private]

The primitive type double is represented by this Class object.

Since:
1.1 The immutable value of this Double.

the wrapped double

Definition at line 107 of file Double.java.


The documentation for this class was generated from the following file: