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 ++++++++++++++++
 java/lang/StrictMath.java                 |   18 +++++++++++
 native/fdlibm/Makefile.am                 |    1 +
 native/fdlibm/s_ilogb.c                   |   47 +++++++++++++++++++++++++++++
 native/jni/java-lang/java_lang_VMDouble.c |    8 +++++
 native/jni/java-lang/java_lang_VMFloat.c  |   10 ++++++
 vm/reference/java/lang/VMDouble.java      |    2 +
 vm/reference/java/lang/VMFloat.java       |    2 +
 10 files changed, 145 insertions(+), 1 deletions(-)
 create mode 100644 native/fdlibm/s_ilogb.c

diff --git a/java/lang/Double.java b/java/lang/Double.java
index 3ae1b01..680d2a2 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 = 1023;
+
+  /**
+   * @since 1.6
+   */
+  public static final int MIN_EXPONENT = -1022;
+
+  /**
    * 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..d0e9f1a 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 = 127;
+
+  /**
+   * @since 1.6
+   */
+  public static final int MIN_EXPONENT = -126;
+
+  /**
    * 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/java/lang/StrictMath.java b/java/lang/StrictMath.java
index 225aaa7..800d00f 100644
--- a/java/lang/StrictMath.java
+++ b/java/lang/StrictMath.java
@@ -2644,4 +2644,22 @@ public final strictfp class StrictMath
     // There's no difference.
     return Math.ulp(f);
   }
+
+  /**
+   * @since 1.6
+   */
+  public static int getExponent(float f)
+  {
+    // There's no difference.
+    return Math.getExponent(f);
+  }
+
+  /**
+   * @since 1.6
+   */
+  public static int getExponent(double d)
+  {
+    // There's no difference.
+    return Math.getExponent(d);
+  }
 }
diff --git a/native/fdlibm/Makefile.am b/native/fdlibm/Makefile.am
index 29bf837..d274fac 100644
--- a/native/fdlibm/Makefile.am
+++ b/native/fdlibm/Makefile.am
@@ -35,6 +35,7 @@ libfdlibm_la_SOURCES =  \
                        sf_fabs.c \
                        s_finite.c \
                        s_floor.c \
+                       s_ilogb.c \
                        s_log1p.c \
                        sf_rint.c \
                        s_rint.c \
diff --git a/native/fdlibm/s_ilogb.c b/native/fdlibm/s_ilogb.c
new file mode 100644
index 0000000..366f3a7
--- /dev/null
+++ b/native/fdlibm/s_ilogb.c
@@ -0,0 +1,47 @@
+
+/* @(#)s_ilogb.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+/* ilogb(double x)
+ * return the binary exponent of non-zero x
+ * ilogb(0) = 0x80000001
+ * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
+ */
+
+#include "fdlibm.h"
+
+#ifdef __STDC__
+       int ilogb(double x)
+#else
+       int ilogb(x)
+       double x;
+#endif
+{
+       int hx,lx,ix;
+
+       GET_HIGH_WORD(hx,x);
+       hx &= 0x7fffffff;
+       if(hx<0x00100000) {
+           GET_LOW_WORD(lx,x);
+           if((hx|lx)==0) 
+               return 0x80000001;      /* ilogb(0) = 0x80000001 */
+           else                        /* subnormal x */
+               if(hx==0) {
+                   for (ix = -1043; lx>0; lx<<=1) ix -=1;
+               } else {
+                   for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
+               }
+           return ix;
+       }
+       else if (hx<0x7ff00000) return (hx>>20)-1023;
+       else return 0x7fffffff;
+}
diff --git a/native/jni/java-lang/java_lang_VMDouble.c 
b/native/jni/java-lang/java_lang_VMDouble.c
index e915a30..6380c07 100644
--- a/native/jni/java-lang/java_lang_VMDouble.c
+++ b/native/jni/java-lang/java_lang_VMDouble.c
@@ -453,3 +453,11 @@ Java_java_lang_VMDouble_parseDouble
 
   return val;
 }
+
+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..cf6f914 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 "fdlibm.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 ilogb(f);
+}
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


Reply via email to