While at it, also add missing Java 1.6 java/lang package constants. Signed-off-by: Pekka Enberg <penb...@kernel.org> --- java/lang/Double.java | 17 ++++++- java/lang/Float.java | 15 ++++++ java/lang/Math.java | 26 ++++++++++ native/fdlibm/fdlibm.h | 1 - native/fdlibm/namespace.h | 1 - native/jni/java-lang/Makefile.am | 1 + .../jni/java-lang/java_lang_VMDouble_getExponent.c | 50 ++++++++++++++++++++ native/jni/java-lang/java_lang_VMFloat.c | 10 ++++ scripts/math_symbols | 1 - vm/reference/java/lang/VMDouble.java | 2 + vm/reference/java/lang/VMFloat.java | 2 + 11 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 native/jni/java-lang/java_lang_VMDouble_getExponent.c
diff --git a/java/lang/Double.java b/java/lang/Double.java index 3ae1b01..674e9f1 100644 --- a/java/lang/Double.java +++ b/java/lang/Double.java @@ -96,7 +96,22 @@ public final class Double extends Number implements Comparable<Double> */ public static final int SIZE = 64; - /** + /** + * @since 1.6 + */ + public static final double MIN_NORMAL = 0x1.0p-1022; + + /** + * @since 1.6 + */ + public static final int MAX_EXPONENT = Math.getExponent(Double.MAX_VALUE); + + /** + * @since 1.6 + */ + public static final int MIN_EXPONENT = Math.getExponent(Double.MIN_NORMAL); + + /** * The primitive type <code>double</code> is represented by this * <code>Class</code> object. * @since 1.1 diff --git a/java/lang/Float.java b/java/lang/Float.java index a4a766e..06525f9 100644 --- a/java/lang/Float.java +++ b/java/lang/Float.java @@ -104,6 +104,21 @@ public final class Float extends Number implements Comparable<Float> public static final int SIZE = 32; /** + * @since 1.6 + */ + public static final float MIN_NORMAL = 0x1.0p-126f; + + /** + * @since 1.6 + */ + public static final int MAX_EXPONENT = Math.getExponent(Float.MAX_VALUE); + + /** + * @since 1.6 + */ + public static final int MIN_EXPONENT = Math.getExponent(Float.MIN_NORMAL); + + /** * Cache representation of 0 */ private static final Float ZERO = new Float(0.0f); diff --git a/java/lang/Math.java b/java/lang/Math.java index 6cf29b4..8dc911c 100644 --- a/java/lang/Math.java +++ b/java/lang/Math.java @@ -1049,4 +1049,30 @@ public final class Math } return Float.intBitsToFloat((newExponent << mantissaBits) | newMantissa); } + + /** + * @since 1.6 + */ + public static int getExponent(float f) + { + if (Float.isNaN(f) || Float.isInfinite(f)) + return Float.MAX_EXPONENT + 1; + else if (f == 0.0f) + return Float.MIN_EXPONENT - 1; + else + return VMFloat.getExponent(f); + } + + /** + * @since 1.6 + */ + public static int getExponent(double d) + { + if (Double.isNaN(d) || Double.isInfinite(d)) + return Double.MAX_EXPONENT + 1; + else if (d == 0.0) + return Double.MIN_EXPONENT - 1; + else + return VMDouble.getExponent(d); + } } diff --git a/native/fdlibm/fdlibm.h b/native/fdlibm/fdlibm.h index fc10ecc..6883808 100644 --- a/native/fdlibm/fdlibm.h +++ b/native/fdlibm/fdlibm.h @@ -150,7 +150,6 @@ extern double sinh __P((double)); extern double tanh __P((double)); extern double exp __P((double)); -extern double frexp __P((double, int *)); extern double ldexp __P((double, int)); extern double log __P((double)); extern double log10 __P((double)); diff --git a/native/fdlibm/namespace.h b/native/fdlibm/namespace.h index 2e6e52b..c4ee642 100644 --- a/native/fdlibm/namespace.h +++ b/native/fdlibm/namespace.h @@ -10,7 +10,6 @@ #define sinh ClasspathMath_sinh #define tanh ClasspathMath_tanh #define exp ClasspathMath_exp -#define frexp ClasspathMath_frexp #define ldexp ClasspathMath_ldexp #define expm1 ClasspathMath_expm1 #define log ClasspathMath_log diff --git a/native/jni/java-lang/Makefile.am b/native/jni/java-lang/Makefile.am index e1bc7ce..b853e72 100644 --- a/native/jni/java-lang/Makefile.am +++ b/native/jni/java-lang/Makefile.am @@ -3,6 +3,7 @@ nativeexeclib_LTLIBRARIES = libjavalang.la libjavalangreflect.la libjavalangmana libjavalang_la_SOURCES = java_lang_VMSystem.c \ java_lang_VMFloat.c \ java_lang_VMDouble.c \ + java_lang_VMDouble_getExponent.c \ java_lang_VMMath.c \ java_lang_VMProcess.c diff --git a/native/jni/java-lang/java_lang_VMDouble_getExponent.c b/native/jni/java-lang/java_lang_VMDouble_getExponent.c new file mode 100644 index 0000000..4f324bc --- /dev/null +++ b/native/jni/java-lang/java_lang_VMDouble_getExponent.c @@ -0,0 +1,50 @@ +/* VMDouble.c - java.lang.VMDouble native functions + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include <config.h> +#include <math.h> + +#include "java_lang_VMDouble.h" + +JNIEXPORT jint JNICALL +Java_java_lang_VMDouble_getExponent + (JNIEnv *env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble d) +{ + return ilogb(d); +} diff --git a/native/jni/java-lang/java_lang_VMFloat.c b/native/jni/java-lang/java_lang_VMFloat.c index acd07ff..bbebe0d 100644 --- a/native/jni/java-lang/java_lang_VMFloat.c +++ b/native/jni/java-lang/java_lang_VMFloat.c @@ -40,6 +40,8 @@ exception statement from your version. */ #include "java_lang_VMFloat.h" +#include <math.h> + /* * Class: java_lang_VMFloat * Method: floatToRawIntBits @@ -69,3 +71,11 @@ Java_java_lang_VMFloat_intBitsToFloat u.i = bits; return u.f; } + +JNIEXPORT jint JNICALL +Java_java_lang_VMFloat_getExponent + (JNIEnv *env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jfloat f) +{ + return ilogbf(f); +} diff --git a/scripts/math_symbols b/scripts/math_symbols index e676a51..6b076a9 100644 --- a/scripts/math_symbols +++ b/scripts/math_symbols @@ -9,7 +9,6 @@ cosh sinh tanh exp -frexp ldexp expm1 log diff --git a/vm/reference/java/lang/VMDouble.java b/vm/reference/java/lang/VMDouble.java index edfa723..6992f44 100644 --- a/vm/reference/java/lang/VMDouble.java +++ b/vm/reference/java/lang/VMDouble.java @@ -119,4 +119,6 @@ final class VMDouble * @throws NullPointerException if str is null */ static native double parseDouble(String str); + + static native int getExponent(double d); } diff --git a/vm/reference/java/lang/VMFloat.java b/vm/reference/java/lang/VMFloat.java index e6e784f..03843ed 100644 --- a/vm/reference/java/lang/VMFloat.java +++ b/vm/reference/java/lang/VMFloat.java @@ -117,4 +117,6 @@ final class VMFloat // the infinitely precise decimal. return (float) Double.parseDouble(str); } + + static native int getExponent(float f); } // class VMFloat -- 1.7.4.1