2015-03-13 18:52:59 +00:00
|
|
|
/* Copyright (c) 2008-2015, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-20 03:18:25 +00:00
|
|
|
package java.lang;
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public final class Double extends Number {
|
2013-02-22 18:55:01 +00:00
|
|
|
public static final Class TYPE = avian.Classes.forCanonicalName("D");
|
2007-07-27 02:39:53 +00:00
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
|
|
|
|
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
|
|
|
|
public static final double NaN = 0.0 / 0.0;
|
|
|
|
|
2014-11-19 11:27:11 +00:00
|
|
|
public static final double MIN_VALUE = 2.22507385850720138309e-308;
|
|
|
|
public static final double MAX_VALUE = 1.79769313486231570815e+308;
|
|
|
|
|
2007-07-20 03:18:25 +00:00
|
|
|
private final double value;
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public Double(String value) {
|
|
|
|
this.value = parseDouble(value);
|
|
|
|
}
|
|
|
|
|
2007-07-20 03:18:25 +00:00
|
|
|
public Double(double value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:50:25 +00:00
|
|
|
public static Double valueOf(double value) {
|
|
|
|
return new Double(value);
|
|
|
|
}
|
|
|
|
|
2008-02-28 15:35:16 +00:00
|
|
|
public static Double valueOf(String s) {
|
|
|
|
return new Double(s);
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public boolean equals(Object o) {
|
|
|
|
return o instanceof Double && ((Double) o).value == value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode() {
|
|
|
|
long v = doubleToRawLongBits(value);
|
|
|
|
return (int) ((v >> 32) ^ (v & 0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return toString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String toString(double v) {
|
2007-10-02 14:58:35 +00:00
|
|
|
byte[] buffer = new byte[20];
|
|
|
|
int numChars = fillBufferWithDouble(v, buffer, 20);
|
|
|
|
return new String(buffer, 0, numChars, false);
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 17:50:26 +00:00
|
|
|
public byte byteValue() {
|
|
|
|
return (byte) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short shortValue() {
|
|
|
|
return (short) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int intValue() {
|
|
|
|
return (int) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long longValue() {
|
|
|
|
return (long) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float floatValue() {
|
|
|
|
return (float) value;
|
|
|
|
}
|
|
|
|
|
2007-07-20 03:18:25 +00:00
|
|
|
public double doubleValue() {
|
|
|
|
return value;
|
|
|
|
}
|
2007-07-29 23:32:23 +00:00
|
|
|
|
2008-02-28 15:35:16 +00:00
|
|
|
public boolean isInfinite() {
|
|
|
|
return isInfinite(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNaN() {
|
|
|
|
return isNaN(value);
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:32:23 +00:00
|
|
|
public static double parseDouble(String s) {
|
2008-02-28 15:35:16 +00:00
|
|
|
int[] numRead = new int[1];
|
|
|
|
double d = doubleFromString(s, numRead);
|
|
|
|
if (numRead[0] == 1) {
|
|
|
|
return d;
|
|
|
|
} else {
|
|
|
|
throw new NumberFormatException(s);
|
|
|
|
}
|
2007-07-29 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 20:45:14 +00:00
|
|
|
public static long doubleToLongBits(double value) {
|
|
|
|
if (isNaN(value)) return 0x7ff8000000000000L;
|
|
|
|
return doubleToRawLongBits(value);
|
|
|
|
}
|
|
|
|
|
2007-10-02 14:58:35 +00:00
|
|
|
public static native int fillBufferWithDouble(double value, byte[] buffer,
|
|
|
|
int charCount);
|
|
|
|
|
2007-08-18 17:15:03 +00:00
|
|
|
public static native long doubleToRawLongBits(double value);
|
|
|
|
|
|
|
|
public static native double longBitsToDouble(long bits);
|
2008-02-28 15:35:16 +00:00
|
|
|
|
|
|
|
public static native boolean isInfinite(double value);
|
|
|
|
|
|
|
|
public static native boolean isNaN(double value);
|
|
|
|
|
|
|
|
public static native double doubleFromString(String s, int[] numRead);
|
2007-07-20 03:18:25 +00:00
|
|
|
}
|