OSDN Git Service

* gnu/gcj/convert/BytesToUnicode.java (getDefaultDecoder): Let
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / Double.java
1 /* Copyright (C) 1998, 1999, 2000  Free Software Foundation
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8  
9 package java.lang;
10
11 /**
12  * @author Andrew Haley <aph@cygnus.com>
13  * @date September 25, 1998.  
14  */
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.
19  */
20
21 public final class Double extends Number
22 {
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;
28
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;
32
33   private double value;
34
35   private static final long serialVersionUID = -9172774392245257468L;
36
37   public native static double parseDouble (String s) 
38     throws NumberFormatException;
39
40   public Double (double v)
41   {
42     value = v;
43   }
44
45   public Double (String s) throws NumberFormatException
46   {
47     value = valueOf (s).doubleValue ();
48   }
49
50   public String toString ()
51   {
52     return toString (value);
53   }
54
55   public boolean equals (Object obj)
56   {
57     if (obj == null)
58       return false;
59
60     if (!(obj instanceof Double))
61       return false;
62
63     Double d = (Double) obj;
64
65     return doubleToLongBits (value) == doubleToLongBits (d.doubleValue ());
66   }
67
68   public int hashCode ()
69   {
70     long v = doubleToLongBits (value);
71     return (int) (v ^ (v >>> 32));
72   }
73
74   public int intValue ()
75   {
76     return (int) value;
77   }
78
79   public long longValue ()
80   {
81     return (long) value;
82   }
83
84   public float floatValue ()
85   {
86     return (float) value;
87   }
88
89   public double doubleValue ()
90   {
91     return value;
92   }
93
94   public byte byteValue ()
95   {
96     return (byte) value;
97   }
98
99   public short shortValue ()
100   {
101     return (short) value;
102   }
103
104   native static String toString (double v, boolean isFloat);
105
106   public static String toString (double v)
107   {
108     return toString (v, false);
109   }
110
111   public static Double valueOf (String s) throws NullPointerException, 
112     NumberFormatException
113   {
114     if (s == null)
115       throw new NullPointerException ();
116
117     return new Double (parseDouble (s));
118   }
119
120   public boolean isNaN ()
121   {
122     return isNaN (value);
123   }
124
125   public static boolean isNaN (double v)
126   {
127     long bits = doubleToLongBits (v);
128     long e = bits & 0x7ff0000000000000L;
129     long f = bits & 0x000fffffffffffffL;
130
131     return e == 0x7ff0000000000000L && f != 0L;
132   }
133
134   public boolean isInfinite ()
135   {
136     return isInfinite (value);
137   }
138
139   public static boolean isInfinite (double v)
140   {
141     long bits = doubleToLongBits (v);
142     long f = bits & 0x7fffffffffffffffL;
143
144     return f == 0x7ff0000000000000L;
145   }
146
147   public static native long doubleToLongBits (double value);
148
149   public static native double longBitsToDouble (long bits);
150 }
151