/[classpath]/classpath/java/lang/Double.java
ViewVC logotype

Diff of /classpath/java/lang/Double.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by mark, Tue Jul 17 23:06:09 2001 UTC revision 1.19 by cbj, Fri Sep 21 04:22:07 2001 UTC
# Line 47  public final class Double extends Number Line 47  public final class Double extends Number
47     * is 5e-324.     * is 5e-324.
48     */     */
49    public static final double MIN_VALUE = 5e-324;    public static final double MIN_VALUE = 5e-324;
50      
51    /**    /**
52     * The maximum positive value a <code>double</code> may represent     * The maximum positive value a <code>double</code> may represent
53     * is 1.7976931348623157e+308.     * is 1.7976931348623157e+308.
54     */     */
55    public static final double MAX_VALUE = 1.7976931348623157e+308;    public static final double MAX_VALUE = 1.7976931348623157e+308;
56        
57    /**    /**
58     * The value of a double representation -1.0/0.0, negative     * The value of a double representation -1.0/0.0, negative
59     * infinity.       * infinity.  
60     */     */
61    public static final double NEGATIVE_INFINITY = -1.0d/0.0d;    public static final double NEGATIVE_INFINITY = -1.0d / 0.0d;
62        
63    /**    /**
64     * The value of a double representing 1.0/0.0, positive infinity.     * The value of a double representing 1.0/0.0, positive infinity.
65     */     */
66    public static final double POSITIVE_INFINITY = 1.0d/0.0d;    public static final double POSITIVE_INFINITY = 1.0d / 0.0d;
67        
68    /**    /**
69     * All IEEE 754 values of NaN have the same value in Java.     * All IEEE 754 values of NaN have the same value in Java.
70     */     */
71    public static final double NaN = 0.0d/0.0d;    public static final double NaN = 0.0d / 0.0d;
72        
73    /**    /**
74     * The primitive type <code>double</code> is represented by this     * The primitive type <code>double</code> is represented by this
75     * <code>Class</code> object.     * <code>Class</code> object.
76     */     */
77    public static final Class TYPE = VMClassLoader.getPrimitiveClass("double");    public static final Class TYPE = VMClassLoader.getPrimitiveClass ("double");
78        
79    /**    /**
80     * The immutable value of this Double.     * The immutable value of this Double.
81     */     */
82    private final double value;    private final double value;
83        
84    /**    /**
85     * Load native routines necessary for this class.       * Load native routines necessary for this class.  
86     */     */
87    static    static
88    {    {
89      if (Configuration.INIT_LOAD_LIBRARY)      if (Configuration.INIT_LOAD_LIBRARY)
90        {        {
91          System.loadLibrary("javalang");          System.loadLibrary ("javalang");
92          initIDs();          initIDs ();
93        }        }
94    }    }
95    
# Line 98  public final class Double extends Number Line 98  public final class Double extends Number
98     * specified.     * specified.
99     *     *
100     * @param value the <code>double</code> argument     * @param value the <code>double</code> argument
101     */     */
102    public Double(double value) {    public Double (double value)
103      {
104      this.value = value;      this.value = value;
105    }    }
106        
107    /**    /**
108     * Create a <code>Double</code> from the specified     * Create a <code>Double</code> from the specified
109     * <code>String</code>.     * <code>String</code>.
# Line 114  public final class Double extends Number Line 115  public final class Double extends Number
115     * @param s the <code>String</code> to convert     * @param s the <code>String</code> to convert
116     * @see #parseDouble(java.lang.String)     * @see #parseDouble(java.lang.String)
117     */     */
118    public Double(String s) throws NumberFormatException    public Double (String s) throws NumberFormatException
119    {    {
120      value = parseDouble(s);      value = parseDouble (s);
121    }    }
122    
123        
124    /**    /**
125     * Convert the <code>double</code> value of this <code>Double</code>     * Convert the <code>double</code> value of this <code>Double</code>
126     * to a <code>String</code>.  This method calls     * to a <code>String</code>.  This method calls
# Line 128  public final class Double extends Number Line 129  public final class Double extends Number
129     * @return the <code>String</code> representation of this <code>Double</code>.     * @return the <code>String</code> representation of this <code>Double</code>.
130     * @see #toString(double)     * @see #toString(double)
131     */     */
132    public String toString()    public String toString ()
133    {    {
134      return toString(value);      return toString (value);
135    }    }
136        
137    /**    /**
138     * If the <code>Object</code> is not <code>null</code>, is an     * If the <code>Object</code> is not <code>null</code>, is an
139     * <code>instanceof</code> <code>Double</code>, and represents     * <code>instanceof</code> <code>Double</code>, and represents
# Line 142  public final class Double extends Number Line 143  public final class Double extends Number
143     * @param obj the object to compare to     * @param obj the object to compare to
144     * @return whether the objects are semantically equal.     * @return whether the objects are semantically equal.
145     */     */
146    public boolean equals(Object obj)    public boolean equals (Object obj)
147    {    {
148      if (!(obj instanceof Double))      if (!(obj instanceof Double))
149        return false;        return false;
# Line 160  public final class Double extends Number Line 161  public final class Double extends Number
161     * where v is defined by: <br>     * where v is defined by: <br>
162     * <code>long v = Double.doubleToLongBits(this.longValue());</code><br>     * <code>long v = Double.doubleToLongBits(this.longValue());</code><br>
163     */     */
164    public int hashCode()    public int hashCode ()
165    {    {
166      long v = doubleToLongBits(value);      long v = doubleToLongBits (value);
167      return (int)(v ^ (v >>> 32));      return (int) (v ^ (v >>> 32));
168    }    }
169        
170    /**    /**
171     * Return the value of this <code>Double</code> when cast to an     * Return the value of this <code>Double</code> when cast to an
172     * <code>int</code>.     * <code>int</code>.
173     */     */
174    public int intValue()    public int intValue ()
175    {    {
176      return (int)value;      return (int) value;
177    }    }
178    
179    /**    /**
180     * Return the value of this <code>Double</code> when cast to a     * Return the value of this <code>Double</code> when cast to a
181     * <code>long</code>.     * <code>long</code>.
182     */         */
183    public long longValue()    public long longValue ()
184    {    {
185      return (long)value;      return (long) value;
186    }    }
187        
188    /**    /**
189     * Return the value of this <code>Double</code> when cast to a     * Return the value of this <code>Double</code> when cast to a
190     * <code>float</code>.     * <code>float</code>.
191     */     */
192    public float floatValue()    public float floatValue ()
193    {    {
194      return (float)value;      return (float) value;
195    }    }
196    
197    /**    /**
198     * Return the primitive <code>double</code> value represented by this     * Return the primitive <code>double</code> value represented by this
199     * <code>Double</code>.     * <code>Double</code>.
200     */         */
201    public double doubleValue()    public double doubleValue ()
202    {    {
203      return value;      return value;
204    }    }
# Line 205  public final class Double extends Number Line 206  public final class Double extends Number
206    /**    /**
207     * Return the value of this <code>Double</code> when cast to a     * Return the value of this <code>Double</code> when cast to a
208     * <code>byte</code>.     * <code>byte</code>.
209     */       */
210    public byte byteValue ()    public byte byteValue ()
211    {    {
212      return (byte) value;      return (byte) value;
# Line 214  public final class Double extends Number Line 215  public final class Double extends Number
215    /**    /**
216     * Return the value of this <code>Double</code> when cast to a     * Return the value of this <code>Double</code> when cast to a
217     * <code>short</code>.     * <code>short</code>.
218     */       */
219    public short shortValue ()    public short shortValue ()
220    {    {
221      return (short) value;      return (short) value;
222    }    }
223        
224    /**    /**
225     * Return the result of calling <code>new Double(java.lang.String)</code>.     * Return the result of calling <code>new Double(java.lang.String)</code>.
226     *     *
# Line 234  public final class Double extends Number Line 235  public final class Double extends Number
235     * @see #Double(java.lang.String)     * @see #Double(java.lang.String)
236     * @see #parseDouble(java.lang.String)     * @see #parseDouble(java.lang.String)
237     */     */
238    public static Double valueOf(String s)    public static Double valueOf (String s) throws NumberFormatException
     throws NumberFormatException  
239    {    {
240      return new Double(s);      return new Double (s);
241    }    }
242    
243    /**    /**
# Line 245  public final class Double extends Number Line 245  public final class Double extends Number
245     * is the same as <code>NaN</code>, otherwise return <code>false</code>.     * is the same as <code>NaN</code>, otherwise return <code>false</code>.
246     * @return whether this <code>Double</code> is <code>NaN</code>.     * @return whether this <code>Double</code> is <code>NaN</code>.
247     */     */
248    public boolean isNaN()    public boolean isNaN ()
249    {    {
250      return isNaN(value);      return isNaN (value);
251    }    }
252        
253    /**    /**
254     * Return <code>true</code> if the <code>double</code> has the same     * Return <code>true</code> if the <code>double</code> has the same
255     * value as <code>NaN</code>, otherwise return <code>false</code>.     * value as <code>NaN</code>, otherwise return <code>false</code>.
# Line 257  public final class Double extends Number Line 257  public final class Double extends Number
257     * @param d the <code>double</code> to compare     * @param d the <code>double</code> to compare
258     * @return whether the argument is <code>NaN</code>.     * @return whether the argument is <code>NaN</code>.
259     */     */
260    public static boolean isNaN(double d)    public static boolean isNaN (double d)
261    {    {
262      return (doubleToLongBits(d) == 0x7ff8000000000000L);      return (doubleToLongBits (d) == 0x7ff8000000000000L);
263    }    }
264    
265    /**    /**
# Line 269  public final class Double extends Number Line 269  public final class Double extends Number
269     *     *
270     * @return whether this <code>Double</code> is (-/+) infinity.     * @return whether this <code>Double</code> is (-/+) infinity.
271     */     */
272    public boolean isInfinite()    public boolean isInfinite ()
273    {    {
274      return isInfinite(value);      return isInfinite (value);
275    }    }
276        
277    /**    /**
278     * Return <code>true</code> if the <code>double</code> has a value     * Return <code>true</code> if the <code>double</code> has a value
279     * equal to either <code>NEGATIVE_INFINITY</code> or     * equal to either <code>NEGATIVE_INFINITY</code> or
# Line 282  public final class Double extends Number Line 282  public final class Double extends Number
282     * @param d the <code>double</code> to compare     * @param d the <code>double</code> to compare
283     * @return whether the argument is (-/+) infinity.     * @return whether the argument is (-/+) infinity.
284     */     */
285    public static boolean isInfinite(double d)    public static boolean isInfinite (double d)
286    {    {
287      return (d == POSITIVE_INFINITY || d == NEGATIVE_INFINITY);      return (d == POSITIVE_INFINITY || d == NEGATIVE_INFINITY);
288    }    }
# Line 306  public final class Double extends Number Line 306  public final class Double extends Number
306     *          in question, or &gt; 0 if it is greater.     *          in question, or &gt; 0 if it is greater.
307     * @since 1.2     * @since 1.2
308     */     */
309    public int compareTo(Double d)    public int compareTo (Double d)
310    {    {
311      return compare(value, d.value);      return compare (value, d.value);
312    }    }
313        
314    /**    /**
315     * Returns 0 if the first argument is equal to the second argument.     * Returns 0 if the first argument is equal to the second argument.
316     * Returns a number less than zero if the first argument is less than the     * Returns a number less than zero if the first argument is less than the
# Line 329  public final class Double extends Number Line 329  public final class Double extends Number
329     *          in question, or &gt; 0 if it is greater.     *          in question, or &gt; 0 if it is greater.
330     * @since 1.4     * @since 1.4
331     */     */
332    public static int compare(double x, double y)    public static int compare (double x, double y)
333    {    {
334      if (isNaN (x))      if (isNaN (x))
335        return isNaN(y) ? 0 : 1;        return isNaN (y) ? 0 : 1;
336      if (isNaN (y))      if (isNaN (y))
337        return -1;        return -1;
338      if ((x == 0.0d) && (y == -0.0d))      if ((x == 0.0d) && (y == -0.0d))
# Line 356  public final class Double extends Number Line 356  public final class Double extends Number
356     *          in question, or &gt; 0 if it is greater.     *          in question, or &gt; 0 if it is greater.
357     * @throws ClassCastException if the argument is not a <code>Double</code>     * @throws ClassCastException if the argument is not a <code>Double</code>
358     */     */
359    public int compareTo(Object o)    public int compareTo (Object o)
360    {    {
361      return compareTo((Double)o);      return compareTo ((Double) o);
362    }    }
363    
364    /**    /**
# Line 408  public final class Double extends Number Line 408  public final class Double extends Number
408     * @param d the <code>double</code> to convert     * @param d the <code>double</code> to convert
409     * @return the <code>String</code> representing the <code>double</code>.     * @return the <code>String</code> representing the <code>double</code>.
410     */     */
411    public static String toString(double d)    public static String toString (double d)
412    {    {
413      return toString (d, false);      return toString (d, false);
414    }    }
415    
416    static native String toString(double d, boolean isFloat);    static native String toString (double d, boolean isFloat);
417    
418    /**    /**
419     * Return the long bits of the specified <code>double</code>.     * Return the long bits of the specified <code>double</code>.
# Line 424  public final class Double extends Number Line 424  public final class Double extends Number
424     * @param value the <code>double</code> to convert     * @param value the <code>double</code> to convert
425     * @return the bits of the <code>double</code>.     * @return the bits of the <code>double</code>.
426     */     */
427    public static native long doubleToLongBits(double value);    public static native long doubleToLongBits (double value);
428    
429    /**    /**
430     * Return the long bits of the specified <code>double</code>.     * Return the long bits of the specified <code>double</code>.
# Line 437  public final class Double extends Number Line 437  public final class Double extends Number
437     * @param value the <code>double</code> to convert     * @param value the <code>double</code> to convert
438     * @return the bits of the <code>double</code>.     * @return the bits of the <code>double</code>.
439     */     */
440    public static native long doubleToRawLongBits(double value);    public static native long doubleToRawLongBits (double value);
441      
442    /**    /**
443     * Return the <code>double</code> represented by the long     * Return the <code>double</code> represented by the long
444     * bits specified.     * bits specified.
# Line 446  public final class Double extends Number Line 446  public final class Double extends Number
446     * @param bits the long bits representing a <code>double</code>     * @param bits the long bits representing a <code>double</code>
447     * @return the <code>double</code> represented by the bits.     * @return the <code>double</code> represented by the bits.
448     */     */
449    public static native double longBitsToDouble(long bits);    public static native double longBitsToDouble (long bits);
450    
451    /**    /**
452     * Parse the specified <code>String</code> as a <code>double</code>.     * Parse the specified <code>String</code> as a <code>double</code>.
# Line 508  public final class Double extends Number Line 508  public final class Double extends Number
508     * @see #NEGATIVE_INFINITY     * @see #NEGATIVE_INFINITY
509     * @since 1.2     * @since 1.2
510     */     */
511    public static double parseDouble (String s)    public static double parseDouble (String s) throws NumberFormatException
     throws NumberFormatException  
512    {    {
513      String t = s.trim();      String t = s.trim ();
514      return parseDouble0 (t);        return parseDouble0 (t);
515    }    }
516    
517    private static native double parseDouble0 (String s)    private static native double parseDouble0 (String s)

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26