]> gcc.gnu.org Git - gcc.git/blob - libjava/java/lang/Double.java
fdcd4202729fa8796639ff00c6426ba3ea3f3e74
[gcc.git] / libjava / java / lang / Double.java
1 /* Copyright (C) 1998, 1999 Red Hat, Inc.
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 native static double doubleValueOf (String s)
36 throws NumberFormatException;
37
38 public Double (double v)
39 {
40 value = v;
41 }
42
43 public Double (String s) throws NumberFormatException
44 {
45 value = valueOf (s).doubleValue ();
46 }
47
48 public String toString ()
49 {
50 return toString (value);
51 }
52
53 public boolean equals (Object obj)
54 {
55 if (obj == null)
56 return false;
57
58 if (!(obj instanceof Double))
59 return false;
60
61 Double d = (Double) obj;
62
63 return doubleToLongBits (value) == doubleToLongBits (d.doubleValue ());
64 }
65
66 public int hashCode ()
67 {
68 long v = doubleToLongBits (value);
69 return (int) (v ^ (v >>> 32));
70 }
71
72 public int intValue ()
73 {
74 return (int) value;
75 }
76
77 public long longValue ()
78 {
79 return (long) value;
80 }
81
82 public float floatValue ()
83 {
84 return (float) value;
85 }
86
87 public double doubleValue ()
88 {
89 return value;
90 }
91
92 public byte byteValue ()
93 {
94 return (byte) value;
95 }
96
97 public short shortValue ()
98 {
99 return (short) value;
100 }
101
102 native static String toString (double v, boolean isFloat);
103
104 public static String toString (double v)
105 {
106 return toString (v, false);
107 }
108
109 public static Double valueOf (String s) throws NullPointerException,
110 NumberFormatException
111 {
112 if (s == null)
113 throw new NullPointerException ();
114
115 return new Double (doubleValueOf (s));
116 }
117
118 public boolean isNaN ()
119 {
120 return isNaN (value);
121 }
122
123 public static boolean isNaN (double v)
124 {
125 long bits = doubleToLongBits (v);
126 long e = bits & 0x7ff0000000000000L;
127 long f = bits & 0x000fffffffffffffL;
128
129 return e == 0x7ff0000000000000L && f != 0L;
130 }
131
132 public boolean isInfinite ()
133 {
134 return isInfinite (value);
135 }
136
137 public static boolean isInfinite (double v)
138 {
139 long bits = doubleToLongBits (v);
140 long f = bits & 0x7fffffffffffffffL;
141
142 return f == 0x7ff0000000000000L;
143 }
144
145 public static native long doubleToLongBits (double value);
146
147 public static native double longBitsToDouble (long bits);
148 }
149
This page took 0.041897 seconds and 4 git commands to generate.