diff options
author | Elliott Hughes <enh@google.com> | 2011-05-19 17:57:08 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-05-19 17:57:08 -0700 |
commit | dc915c69ba2495dd2cf965d16058d0b13762142c (patch) | |
tree | 2a6028983527fa694a89c145d8122706a1c37e75 | |
parent | dbde5bd893290c02bb289460fc61e48eda63daa2 (diff) | |
download | libcore-dc915c69ba2495dd2cf965d16058d0b13762142c.zip libcore-dc915c69ba2495dd2cf965d16058d0b13762142c.tar.gz libcore-dc915c69ba2495dd2cf965d16058d0b13762142c.tar.bz2 |
Move the floating-point parsing code, and tidy up some documentation.
Change-Id: Ibdc1716847f4c6a85a7c24766feffc8768819cef
-rw-r--r-- | luni/src/main/java/java/lang/Double.java | 44 | ||||
-rw-r--r-- | luni/src/main/java/java/lang/Float.java | 45 | ||||
-rw-r--r-- | luni/src/main/java/java/lang/HexStringParser.java (renamed from luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java) | 6 | ||||
-rw-r--r-- | luni/src/main/java/java/lang/StringToReal.java (renamed from luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java) | 6 | ||||
-rw-r--r-- | luni/src/main/java/java/math/MathContext.java | 6 | ||||
-rw-r--r-- | luni/src/main/native/Register.cpp | 4 | ||||
-rw-r--r-- | luni/src/main/native/java_lang_StringToReal.cpp (renamed from luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp) | 13 | ||||
-rw-r--r-- | luni/src/main/native/sub.mk | 2 |
8 files changed, 44 insertions, 82 deletions
diff --git a/luni/src/main/java/java/lang/Double.java b/luni/src/main/java/java/lang/Double.java index 1748128..9f8ce7e 100644 --- a/luni/src/main/java/java/lang/Double.java +++ b/luni/src/main/java/java/lang/Double.java @@ -166,31 +166,18 @@ public final class Double extends Number implements Comparable<Double> { } /** - * Converts the specified double value to a binary representation conforming - * to the IEEE 754 floating-point double precision bit layout. All - * <em>Not-a-Number (NaN)</em> values are converted to a single NaN - * representation ({@code 0x7ff8000000000000L}). - * - * @param value - * the double value to convert. - * @return the IEEE 754 floating-point double precision representation of - * {@code value}. - * @see #doubleToRawLongBits(double) - * @see #longBitsToDouble(long) + * Returns an integer corresponding to the bits of the given + * <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> double precision + * {@code value}. All <em>Not-a-Number (NaN)</em> values are converted to a single NaN + * representation ({@code 0x7ff8000000000000L}) (compare to {@link #doubleToRawLongBits}). */ public static native long doubleToLongBits(double value); /** - * Converts the specified double value to a binary representation conforming - * to the IEEE 754 floating-point double precision bit layout. - * <em>Not-a-Number (NaN)</em> values are preserved. - * - * @param value - * the double value to convert. - * @return the IEEE 754 floating-point double precision representation of - * {@code value}. - * @see #doubleToLongBits(double) - * @see #longBitsToDouble(long) + * Returns an integer corresponding to the bits of the given + * <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> double precision + * {@code value}. <em>Not-a-Number (NaN)</em> values are preserved (compare + * to {@link #doubleToLongBits}). */ public static native long doubleToRawLongBits(double value); @@ -286,15 +273,8 @@ public final class Double extends Number implements Comparable<Double> { } /** - * Converts the specified IEEE 754 floating-point double precision bit - * pattern to a Java double value. - * - * @param bits - * the IEEE 754 floating-point double precision representation of - * a double value. - * @return the double value converted from {@code bits}. - * @see #doubleToLongBits(double) - * @see #doubleToRawLongBits(double) + * Returns the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> + * double precision float corresponding to the given {@code bits}. */ public static native double longBitsToDouble(long bits); @@ -313,7 +293,7 @@ public final class Double extends Number implements Comparable<Double> { * if {@code string} cannot be parsed as a double value. */ public static double parseDouble(String string) throws NumberFormatException { - return org.apache.harmony.luni.util.FloatingPointParser.parseDouble(string); + return StringToReal.parseDouble(string); } @Override @@ -421,7 +401,7 @@ public final class Double extends Number implements Comparable<Double> { */ public static String toHexString(double d) { /* - * Reference: http://en.wikipedia.org/wiki/IEEE_754 + * Reference: http://en.wikipedia.org/wiki/IEEE_754-1985 */ if (d != d) { return "NaN"; diff --git a/luni/src/main/java/java/lang/Float.java b/luni/src/main/java/java/lang/Float.java index bbbb7f7..e4dc140 100644 --- a/luni/src/main/java/java/lang/Float.java +++ b/luni/src/main/java/java/lang/Float.java @@ -195,31 +195,18 @@ public final class Float extends Number implements Comparable<Float> { } /** - * Converts the specified float value to a binary representation conforming - * to the IEEE 754 floating-point single precision bit layout. All - * <em>Not-a-Number (NaN)</em> values are converted to a single NaN - * representation ({@code 0x7fc00000}). - * - * @param value - * the float value to convert. - * @return the IEEE 754 floating-point single precision representation of - * {@code value}. - * @see #floatToRawIntBits(float) - * @see #intBitsToFloat(int) + * Returns an integer corresponding to the bits of the given + * <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> single precision + * float {@code value}. All <em>Not-a-Number (NaN)</em> values are converted to a single NaN + * representation ({@code 0x7fc00000}) (compare to {@link #floatToRawIntBits}). */ public static native int floatToIntBits(float value); /** - * Converts the specified float value to a binary representation conforming - * to the IEEE 754 floating-point single precision bit layout. - * <em>Not-a-Number (NaN)</em> values are preserved. - * - * @param value - * the float value to convert. - * @return the IEEE 754 floating-point single precision representation of - * {@code value}. - * @see #floatToIntBits(float) - * @see #intBitsToFloat(int) + * Returns an integer corresponding to the bits of the given + * <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> single precision + * float {@code value}. <em>Not-a-Number (NaN)</em> values are preserved (compare + * to {@link #floatToIntBits}). */ public static native int floatToRawIntBits(float value); @@ -239,15 +226,8 @@ public final class Float extends Number implements Comparable<Float> { } /** - * Converts the specified IEEE 754 floating-point single precision bit - * pattern to a Java float value. - * - * @param bits - * the IEEE 754 floating-point single precision representation of - * a float value. - * @return the float value converted from {@code bits}. - * @see #floatToIntBits(float) - * @see #floatToRawIntBits(float) + * Returns the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> + * single precision float corresponding to the given {@code bits}. */ public static native float intBitsToFloat(int bits); @@ -318,8 +298,7 @@ public final class Float extends Number implements Comparable<Float> { * @since 1.2 */ public static float parseFloat(String string) throws NumberFormatException { - return org.apache.harmony.luni.util.FloatingPointParser - .parseFloat(string); + return StringToReal.parseFloat(string); } @Override @@ -429,7 +408,7 @@ public final class Float extends Number implements Comparable<Float> { */ public static String toHexString(float f) { /* - * Reference: http://en.wikipedia.org/wiki/IEEE_754 + * Reference: http://en.wikipedia.org/wiki/IEEE_754-1985 */ if (f != f) { return "NaN"; diff --git a/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java b/luni/src/main/java/java/lang/HexStringParser.java index 9e20a16..8593b99 100644 --- a/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java +++ b/luni/src/main/java/java/lang/HexStringParser.java @@ -15,13 +15,17 @@ * limitations under the License. */ -package org.apache.harmony.luni.util; +package java.lang; import java.util.regex.Matcher; import java.util.regex.Pattern; /* * Parses hex string to a single or double precision floating point number. + * + * TODO: rewrite this! + * + * @hide */ final class HexStringParser { diff --git a/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java b/luni/src/main/java/java/lang/StringToReal.java index e08e560..97f6d6b 100644 --- a/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java +++ b/luni/src/main/java/java/lang/StringToReal.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.harmony.luni.util; - +package java.lang; /** * Used to parse a string and return either a single or double precision * floating point number. + * @hide */ -public final class FloatingPointParser { +final class StringToReal { private static final class StringExponentPair { String s; diff --git a/luni/src/main/java/java/math/MathContext.java b/luni/src/main/java/java/math/MathContext.java index 24ccb29..6f3f1ed 100644 --- a/luni/src/main/java/java/math/MathContext.java +++ b/luni/src/main/java/java/math/MathContext.java @@ -30,21 +30,21 @@ public final class MathContext implements Serializable { private static final long serialVersionUID = 5579720004786848255L; /** - * A {@code MathContext} which corresponds to the IEEE 754r quadruple + * A {@code MathContext} which corresponds to the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> quadruple * decimal precision format: 34 digit precision and * {@link RoundingMode#HALF_EVEN} rounding. */ public static final MathContext DECIMAL128 = new MathContext(34, RoundingMode.HALF_EVEN); /** - * A {@code MathContext} which corresponds to the IEEE 754r single decimal + * A {@code MathContext} which corresponds to the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> single decimal * precision format: 7 digit precision and {@link RoundingMode#HALF_EVEN} * rounding. */ public static final MathContext DECIMAL32 = new MathContext(7, RoundingMode.HALF_EVEN); /** - * A {@code MathContext} which corresponds to the IEEE 754r double decimal + * A {@code MathContext} which corresponds to the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a> double decimal * precision format: 16 digit precision and {@link RoundingMode#HALF_EVEN} * rounding. */ diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp index f04082a..a637a73 100644 --- a/luni/src/main/native/Register.cpp +++ b/luni/src/main/native/Register.cpp @@ -29,6 +29,7 @@ extern int register_java_lang_Math(JNIEnv* env); extern int register_java_lang_ProcessManager(JNIEnv* env); extern int register_java_lang_RealToString(JNIEnv* env); extern int register_java_lang_StrictMath(JNIEnv* env); +extern int register_java_lang_StringToReal(JNIEnv* env); extern int register_java_lang_System(JNIEnv* env); extern int register_java_math_NativeBN(JNIEnv* env); extern int register_java_nio_ByteOrder(JNIEnv* env); @@ -55,7 +56,6 @@ extern int register_libcore_io_OsConstants(JNIEnv* env); extern int register_libcore_io_Posix(JNIEnv* env); extern int register_libcore_net_RawSocket(JNIEnv* env); extern int register_org_apache_harmony_dalvik_NativeTestTarget(JNIEnv* env); -extern int register_org_apache_harmony_luni_util_FloatingPointParser(JNIEnv* env); extern int register_org_apache_harmony_xml_ExpatParser(JNIEnv* env); extern int register_org_apache_harmony_xnet_provider_jsse_NativeCrypto(JNIEnv* env); @@ -74,6 +74,7 @@ int registerCoreLibrariesJni(JNIEnv* env) { register_java_lang_ProcessManager(env) != -1 && register_java_lang_RealToString(env) != -1 && register_java_lang_StrictMath(env) != -1 && + register_java_lang_StringToReal(env) != -1 && register_java_lang_System(env) != -1 && register_java_math_NativeBN(env) != -1 && register_java_nio_ByteOrder(env) != -1 && @@ -100,7 +101,6 @@ int registerCoreLibrariesJni(JNIEnv* env) { register_libcore_io_Posix(env) != -1 && register_libcore_net_RawSocket(env) != -1 && register_org_apache_harmony_dalvik_NativeTestTarget(env) != -1 && - register_org_apache_harmony_luni_util_FloatingPointParser(env) != -1 && register_org_apache_harmony_xml_ExpatParser(env) != -1 && register_org_apache_harmony_xnet_provider_jsse_NativeCrypto(env) != -1 && true; diff --git a/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp b/luni/src/main/native/java_lang_StringToReal.cpp index 48c0a77..06aa076 100644 --- a/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp +++ b/luni/src/main/native/java_lang_StringToReal.cpp @@ -989,7 +989,7 @@ OutOfMemory: return z; } -static jfloat FloatingPointParser_parseFltImpl(JNIEnv* env, jclass, jstring s, jint e) { +static jfloat StringToReal_parseFltImpl(JNIEnv* env, jclass, jstring s, jint e) { ScopedUtfChars str(env, s); if (str.c_str() == NULL) { return 0.0; @@ -997,7 +997,7 @@ static jfloat FloatingPointParser_parseFltImpl(JNIEnv* env, jclass, jstring s, j return createFloat(env, str.c_str(), e); } -static jdouble FloatingPointParser_parseDblImpl(JNIEnv* env, jclass, jstring s, jint e) { +static jdouble StringToReal_parseDblImpl(JNIEnv* env, jclass, jstring s, jint e) { ScopedUtfChars str(env, s); if (str.c_str() == NULL) { return 0.0; @@ -1006,10 +1006,9 @@ static jdouble FloatingPointParser_parseDblImpl(JNIEnv* env, jclass, jstring s, } static JNINativeMethod gMethods[] = { - NATIVE_METHOD(FloatingPointParser, parseFltImpl, "(Ljava/lang/String;I)F"), - NATIVE_METHOD(FloatingPointParser, parseDblImpl, "(Ljava/lang/String;I)D"), + NATIVE_METHOD(StringToReal, parseFltImpl, "(Ljava/lang/String;I)F"), + NATIVE_METHOD(StringToReal, parseDblImpl, "(Ljava/lang/String;I)D"), }; -int register_org_apache_harmony_luni_util_FloatingPointParser(JNIEnv* env) { - return jniRegisterNativeMethods(env, "org/apache/harmony/luni/util/FloatingPointParser", - gMethods, NELEM(gMethods)); +int register_java_lang_StringToReal(JNIEnv* env) { + return jniRegisterNativeMethods(env, "java/lang/StringToReal", gMethods, NELEM(gMethods)); } diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk index e0d18c4..9535ce6 100644 --- a/luni/src/main/native/sub.mk +++ b/luni/src/main/native/sub.mk @@ -18,6 +18,7 @@ LOCAL_SRC_FILES := \ java_lang_ProcessManager.cpp \ java_lang_RealToString.cpp \ java_lang_StrictMath.cpp \ + java_lang_StringToReal.cpp \ java_lang_System.cpp \ java_math_NativeBN.cpp \ java_nio_ByteOrder.cpp \ @@ -43,7 +44,6 @@ LOCAL_SRC_FILES := \ libcore_io_OsConstants.cpp \ libcore_io_Posix.cpp \ libcore_net_RawSocket.cpp \ - org_apache_harmony_luni_util_FloatingPointParser.cpp \ org_apache_harmony_xml_ExpatParser.cpp \ org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp \ readlink.cpp \ |