1 /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Andrew Haley <aph@cygnus.com>
13 * @date September 25, 1998.
15 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
16 * "The Java Language Specification", ISBN 0-201-63451-1
17 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
18 * Status: Believed complete and correct.
21 public final class Double extends Number
23 public static final double MIN_VALUE = 5e-324;
24 public static final double MAX_VALUE = 1.7976931348623157e+308;
25 public static final double NEGATIVE_INFINITY = -1.0d/0.0d;
26 public static final double POSITIVE_INFINITY = 1.0d/0.0d;
27 public static final double NaN = 0.0d/0.0d;
29 // This initialization is seemingly circular, but it is accepted
30 // by javac, and is handled specially by gcc.
31 public static final Class TYPE = double.class;
35 private static final long serialVersionUID = -9172774392245257468L;
37 public native static double parseDouble (String s)
38 throws NumberFormatException;
40 public Double (double v)
45 public Double (String s) throws NumberFormatException
47 value = valueOf (s).doubleValue ();
50 public String toString ()
52 return toString (value);
55 public boolean equals (Object obj)
60 if (!(obj instanceof Double))
63 Double d = (Double) obj;
65 return doubleToLongBits (value) == doubleToLongBits (d.doubleValue ());
68 public int hashCode ()
70 long v = doubleToLongBits (value);
71 return (int) (v ^ (v >>> 32));
74 public int intValue ()
79 public long longValue ()
84 public float floatValue ()
89 public double doubleValue ()
94 public byte byteValue ()
99 public short shortValue ()
101 return (short) value;
104 native static String toString (double v, boolean isFloat);
106 public static String toString (double v)
108 return toString (v, false);
111 public static Double valueOf (String s) throws NullPointerException,
112 NumberFormatException
115 throw new NullPointerException ();
117 return new Double (parseDouble (s));
120 public boolean isNaN ()
122 return isNaN (value);
125 public static boolean isNaN (double v)
127 long bits = doubleToLongBits (v);
128 long e = bits & 0x7ff0000000000000L;
129 long f = bits & 0x000fffffffffffffL;
131 return e == 0x7ff0000000000000L && f != 0L;
134 public boolean isInfinite ()
136 return isInfinite (value);
139 public static boolean isInfinite (double v)
141 long bits = doubleToLongBits (v);
142 long f = bits & 0x7fffffffffffffffL;
144 return f == 0x7ff0000000000000L;
147 public static native long doubleToLongBits (double value);
149 public static native double longBitsToDouble (long bits);