I'd welcome any comments on the attached patch,
which separates the Math native methods into a separate
class, VMMath, so that they can optionally be replaced
by the VM.  This fixes PR22198.

I also have code for most of the new Math methods here
as well.  However, I've had some problems in using the methods
for these in fdlibm.  Namely,

a) Existing methods such as sinh produce a linking error for
ClasspathSinH or something like that which seems to be something
to do with namespace.h.

b) Two of the methods require an update from 5.1 to 5.3 of fdlibm.
Merely adding the two new c files to Makefile.am didn't seem to work
(they don't seem to be being built).  The methods are log1p and expm1.

I'd appreciate some info. from anyone who knows how fdlibm works with
Classpath.  At worst, I can simply commit the code I have and someone
else can link these in, but it would be nice to know how to do this.
I'm guessing that mprec is separate from fdlibm although it appears in
the same directory; I recall there was talk of an update of this as well
to probably handle 64-bit support.

Changelog:

2006-02-06  Andrew John Hughes  <[EMAIL PROTECTED]>

        * include/Makefile.am:
        Swapped Math.h for VMMath.h
        * include/java_lang_Math.h:
        Removed.
        * include/java_lang_VMMath.h:
        New autogenerated header for the new class.
        * java/lang/Math.java:
        (sin(double)): Changed to link to VMMath.
        (cos(double)): Changed to link to VMMath.
        (tan(double)): Changed to link to VMMath.
        (asin(double)): Changed to link to VMMath.
        (acos(double)): Changed to link to VMMath.
        (atan(double)): Changed to link to VMMath.
        (atan2(double)): Changed to link to VMMath.
        (exp(double)): Changed to link to VMMath.
        (log(double)): Changed to link to VMMath.
        (sqrt(double)): Changed to link to VMMath.
        (pow(double,double)): Changed to link to VMMath.
        (IEEEremainder(double,double)): Changed to link to VMMath.
        (ceil(double)): Changed to link to VMMath.
        (floor(double)): Changed to link to VMMath.
        (rint(double)): Changed to link to VMMath.
        * native/jni/java-lang/Makefile.am:
        Replaced java_lang_Math.c with java_lang_VMMath.c
        * native/jni/java-lang/java_lang_Math.c:
        Removed.
        * native/jni/java-lang/java_lang_VMMath.c:
        Renamed from java_lang_Math.c.
        * vm/reference/java/lang/VMMath.java:
        New class.
        (sin(double)): New native method.
        (cos(double)): New native method.
        (tan(double)): New native method.
        (asin(double)): New native method.
        (acos(double)): New native method.
        (atan(double)): New native method.
        (atan2(double)): New native method.
        (exp(double)): New native method.
        (log(double)): New native method.
        (sqrt(double)): New native method.
        (pow(double,double)): New native method.
        (IEEEremainder(double,double)): New native method.
        (ceil(double)): New native method.
        (floor(double)): New native method.
        (rint(double)): New native method.

-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: include/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/include/Makefile.am,v
retrieving revision 1.52
diff -u -3 -p -u -r1.52 Makefile.am
--- include/Makefile.am 4 Jan 2006 16:37:55 -0000       1.52
+++ include/Makefile.am 6 Feb 2006 21:57:01 -0000
@@ -127,9 +127,9 @@ $(top_srcdir)/include/gnu_java_nio_chars
 $(top_srcdir)/include/java_io_VMFile.h \
 $(top_srcdir)/include/java_io_VMObjectInputStream.h \
 $(top_srcdir)/include/java_io_VMObjectStreamClass.h \
-$(top_srcdir)/include/java_lang_Math.h \
 $(top_srcdir)/include/java_lang_VMDouble.h \
 $(top_srcdir)/include/java_lang_VMFloat.h \
+$(top_srcdir)/include/java_lang_VMMath.h \
 $(top_srcdir)/include/java_lang_VMProcess.h \
 $(top_srcdir)/include/java_lang_VMSystem.h \
 $(top_srcdir)/include/java_lang_reflect_Array.h \
@@ -178,8 +178,8 @@ $(top_srcdir)/include/java_io_VMObjectIn
        $(JAVAH) -o $@ java.io.VMObjectInputStream
 $(top_srcdir)/include/java_io_VMObjectStreamClass.h: 
$(top_srcdir)/vm/reference/java/io/VMObjectStreamClass.java
        $(JAVAH) -o $@ java.io.VMObjectStreamClass
-$(top_srcdir)/include/java_lang_Math.h: $(top_srcdir)/java/lang/Math.java
-       $(JAVAH) -o $@ java.lang.Math
+$(top_srcdir)/include/java_lang_VMMath.h: 
$(top_srcdir)/vm/reference/java/lang/VMMath.java
+       $(JAVAH) -o $@ java.lang.VMMath
 $(top_srcdir)/include/java_lang_VMDouble.h: 
$(top_srcdir)/vm/reference/java/lang/VMDouble.java
        $(JAVAH) -o $@ java.lang.VMDouble
 $(top_srcdir)/include/java_lang_VMFloat.h: 
$(top_srcdir)/vm/reference/java/lang/VMFloat.java
Index: include/java_lang_Math.h
===================================================================
RCS file: include/java_lang_Math.h
diff -N include/java_lang_Math.h
--- include/java_lang_Math.h    11 Nov 2004 17:31:31 -0000      1.4
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,37 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-
-#ifndef __java_lang_Math__
-#define __java_lang_Math__
-
-#include <jni.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_sin (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_cos (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_tan (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_asin (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_acos (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_atan (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_atan2 (JNIEnv *env, jclass, 
jdouble, jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_exp (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_log (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_pow (JNIEnv *env, jclass, 
jdouble, jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_IEEEremainder (JNIEnv *env, 
jclass, jdouble, jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_ceil (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_floor (JNIEnv *env, jclass, 
jdouble);
-JNIEXPORT jdouble JNICALL Java_java_lang_Math_rint (JNIEnv *env, jclass, 
jdouble);
-#undef java_lang_Math_E
-#define java_lang_Math_E 0x1.5bf0a8b145769p+1
-#undef java_lang_Math_PI
-#define java_lang_Math_PI 0x1.921fb54442d18p+1
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __java_lang_Math__ */
Index: include/java_lang_VMMath.h
===================================================================
RCS file: include/java_lang_VMMath.h
diff -N include/java_lang_VMMath.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ include/java_lang_VMMath.h  6 Feb 2006 21:57:01 -0000
@@ -0,0 +1,33 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __java_lang_VMMath__
+#define __java_lang_VMMath__
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_sin (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_cos (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_tan (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_asin (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_acos (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_atan (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_atan2 (JNIEnv *env, jclass, 
jdouble, jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_exp (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_log (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_sqrt (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_pow (JNIEnv *env, jclass, 
jdouble, jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_IEEEremainder (JNIEnv *env, 
jclass, jdouble, jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_ceil (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_floor (JNIEnv *env, jclass, 
jdouble);
+JNIEXPORT jdouble JNICALL Java_java_lang_VMMath_rint (JNIEnv *env, jclass, 
jdouble);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __java_lang_VMMath__ */
Index: java/lang/Math.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Math.java,v
retrieving revision 1.19
diff -u -3 -p -u -r1.19 Math.java
--- java/lang/Math.java 2 Jul 2005 20:32:38 -0000       1.19
+++ java/lang/Math.java 6 Feb 2006 21:57:02 -0000
@@ -1,4 +1,4 @@
-/* java.lang.Math -- common mathematical functions, native allowed
+/* java.lang.Math -- common mathematical functions, native allowed (VMMath)
    Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -52,6 +52,7 @@ import java.util.Random;
  * @author Paul Fisher
  * @author John Keiser
  * @author Eric Blake ([EMAIL PROTECTED])
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
  * @since 1.0
  */
 public final class Math
@@ -298,7 +299,10 @@ public final class Math
    * @param a the angle (in radians)
    * @return sin(a)
    */
-  public static native double sin(double a);
+  public static double sin(double a)
+  {
+    return VMMath.sin(a);
+  }
 
   /**
    * The trigonometric function <em>cos</em>. The cosine of NaN or infinity is
@@ -307,7 +311,10 @@ public final class Math
    * @param a the angle (in radians)
    * @return cos(a)
    */
-  public static native double cos(double a);
+  public static double cos(double a)
+  {
+    return VMMath.cos(a);
+  }
 
   /**
    * The trigonometric function <em>tan</em>. The tangent of NaN or infinity
@@ -317,7 +324,10 @@ public final class Math
    * @param a the angle (in radians)
    * @return tan(a)
    */
-  public static native double tan(double a);
+  public static double tan(double a)
+  {
+    return VMMath.tan(a);
+  }
 
   /**
    * The trigonometric function <em>arcsin</em>. The range of angles returned
@@ -328,7 +338,10 @@ public final class Math
    * @param a the sin to turn back into an angle
    * @return arcsin(a)
    */
-  public static native double asin(double a);
+  public static double asin(double a)
+  {
+    return VMMath.asin(a);
+  }
 
   /**
    * The trigonometric function <em>arccos</em>. The range of angles returned
@@ -339,7 +352,10 @@ public final class Math
    * @param a the cos to turn back into an angle
    * @return arccos(a)
    */
-  public static native double acos(double a);
+  public static double acos(double a)
+  {
+    return VMMath.acos(a);
+  }
 
   /**
    * The trigonometric function <em>arcsin</em>. The range of angles returned
@@ -351,7 +367,10 @@ public final class Math
    * @return arcsin(a)
    * @see #atan2(double, double)
    */
-  public static native double atan(double a);
+  public static double atan(double a)
+  {
+    return VMMath.atan(a);
+  }
 
   /**
    * A special version of the trigonometric function <em>arctan</em>, for
@@ -400,7 +419,10 @@ public final class Math
    * @return <em>theta</em> in the conversion of (x, y) to (r, theta)
    * @see #atan(double)
    */
-  public static native double atan2(double y, double x);
+  public static double atan2(double y, double x)
+  {
+    return VMMath.atan2(y,x);
+  }
 
   /**
    * Take <em>e</em><sup>a</sup>.  The opposite of <code>log()</code>. If the
@@ -414,7 +436,10 @@ public final class Math
    * @see #log(double)
    * @see #pow(double, double)
    */
-  public static native double exp(double a);
+  public static double exp(double a)
+  {
+    return VMMath.exp(a);
+  }
 
   /**
    * Take ln(a) (the natural log).  The opposite of <code>exp()</code>. If the
@@ -430,7 +455,10 @@ public final class Math
    * @return the natural log of <code>a</code>
    * @see #exp(double)
    */
-  public static native double log(double a);
+  public static double log(double a)
+  {
+    return VMMath.log(a);
+  }
 
   /**
    * Take a square root. If the argument is NaN or negative, the result is
@@ -438,13 +466,18 @@ public final class Math
    * infinity; and if the result is either zero, the result is the same.
    * This is accurate within the limits of doubles.
    *
-   * <p>For other roots, use pow(a, 1 / rootNumber).
+   * <p>For a cube root, use <code>cbrt</code>.  For other roots, use
+   * <code>pow(a, 1 / rootNumber)</code>.</p>
    *
    * @param a the numeric argument
    * @return the square root of the argument
+   * @see #cbrt(double)
    * @see #pow(double, double)
    */
-  public static native double sqrt(double a);
+  public static double sqrt(double a)
+  {
+    return VMMath.sqrt(a);
+  }
 
   /**
    * Raise a number to a power. Special cases:<ul>
@@ -514,7 +547,10 @@ public final class Math
    * @param b the power to raise it to
    * @return a<sup>b</sup>
    */
-  public static native double pow(double a, double b);
+  public static double pow(double a, double b)
+  {
+    return VMMath.pow(a,b);
+  }
 
   /**
    * Get the IEEE 754 floating point remainder on two numbers. This is the
@@ -530,7 +566,10 @@ public final class Math
    * @return the IEEE 754-defined floating point remainder of x/y
    * @see #rint(double)
    */
-  public static native double IEEEremainder(double x, double y);
+  public static double IEEEremainder(double x, double y)
+  {
+    return VMMath.IEEEremainder(x,y);
+  }
 
   /**
    * Take the nearest integer that is that is greater than or equal to the
@@ -541,7 +580,10 @@ public final class Math
    * @param a the value to act upon
    * @return the nearest integer &gt;= <code>a</code>
    */
-  public static native double ceil(double a);
+  public static double ceil(double a)
+  {
+    return VMMath.ceil(a);
+  }
 
   /**
    * Take the nearest integer that is that is less than or equal to the
@@ -551,7 +593,10 @@ public final class Math
    * @param a the value to act upon
    * @return the nearest integer &lt;= <code>a</code>
    */
-  public static native double floor(double a);
+  public static double floor(double a)
+  {
+    return VMMath.floor(a);
+  }
 
   /**
    * Take the nearest integer to the argument.  If it is exactly between
@@ -561,7 +606,10 @@ public final class Math
    * @param a the value to act upon
    * @return the nearest integer to <code>a</code>
    */
-  public static native double rint(double a);
+  public static double rint(double a)
+  {
+    return VMMath.rint(a);
+  }
 
   /**
    * Take the nearest integer to the argument.  This is equivalent to
@@ -647,4 +695,5 @@ public final class Math
   {
     return (rads * 180) / PI;
   }
+
 }
Index: native/jni/java-lang/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-lang/Makefile.am,v
retrieving revision 1.14
diff -u -3 -p -u -r1.14 Makefile.am
--- native/jni/java-lang/Makefile.am    25 Jan 2006 10:40:12 -0000      1.14
+++ native/jni/java-lang/Makefile.am    6 Feb 2006 21:57:03 -0000
@@ -3,7 +3,7 @@ nativelib_LTLIBRARIES = libjavalang.la l
 libjavalang_la_SOURCES = java_lang_VMSystem.c \
                         java_lang_VMFloat.c \
                         java_lang_VMDouble.c \
-                        java_lang_Math.c \
+                        java_lang_VMMath.c \
                         java_lang_VMProcess.c
 
 libjavalang_la_LIBADD = $(wildcard $(top_builddir)/native/fdlibm/*.lo) \
Index: native/jni/java-lang/java_lang_Math.c
===================================================================
RCS file: native/jni/java-lang/java_lang_Math.c
diff -N native/jni/java-lang/java_lang_Math.c
--- native/jni/java-lang/java_lang_Math.c       2 Jul 2005 20:32:55 -0000       
1.9
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,161 +0,0 @@
-/* Math.c - java.lang.Math native functions
-   Copyright (C) 1998, 1999, 2004 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 <java_lang_Math.h>
-#include <fdlibm.h>
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_sin
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return sin (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_cos
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return cos (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_tan
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return tan (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_asin
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return asin (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_acos
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return acos (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_atan
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return atan (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_atan2
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble y, jdouble x)
-{
-  return atan2 (y, x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_exp
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return exp (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_log
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return log (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_sqrt
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return sqrt (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_pow
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y)
-{
-  return pow (x, y);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_IEEEremainder
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y)
-{
-  return remainder (x, y);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_ceil
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return ceil (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_floor
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return floor (x);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_java_lang_Math_rint
-  (JNIEnv * env __attribute__ ((__unused__)),
-   jclass cls __attribute__ ((__unused__)), jdouble x)
-{
-  return rint (x);
-}
Index: native/jni/java-lang/java_lang_VMMath.c
===================================================================
RCS file: native/jni/java-lang/java_lang_VMMath.c
diff -N native/jni/java-lang/java_lang_VMMath.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ native/jni/java-lang/java_lang_VMMath.c     6 Feb 2006 21:57:03 -0000
@@ -0,0 +1,162 @@
+/* VMMath.c - java.lang.VMMath native functions
+   Copyright (C) 1998, 1999, 2004, 2006 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 <java_lang_VMMath.h>
+#include <fdlibm.h>
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_sin
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return sin (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_cos
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return cos (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_tan
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return tan (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_asin
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return asin (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_acos
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return acos (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_atan
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return atan (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_atan2
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble y, jdouble x)
+{
+  return atan2 (y, x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_exp
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return exp (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_log
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return log (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_sqrt
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return sqrt (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_pow
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y)
+{
+  return pow (x, y);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_IEEEremainder
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y)
+{
+  return remainder (x, y);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_ceil
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return ceil (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_floor
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return floor (x);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_VMMath_rint
+  (JNIEnv * env __attribute__ ((__unused__)),
+   jclass cls __attribute__ ((__unused__)), jdouble x)
+{
+  return rint (x);
+}
+
Index: vm/reference/java/lang/VMMath.java
===================================================================
RCS file: vm/reference/java/lang/VMMath.java
diff -N vm/reference/java/lang/VMMath.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ vm/reference/java/lang/VMMath.java  6 Feb 2006 21:57:03 -0000
@@ -0,0 +1,325 @@
+/* VMMath.java -- Common mathematical functions.
+   Copyright (C) 2006  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. */
+
+
+package java.lang;
+
+import gnu.classpath.Configuration;
+
+class VMMath
+{
+
+  static
+  {
+    if (Configuration.INIT_LOAD_LIBRARY)
+      System.loadLibrary("javanet");
+  }
+
+  /**
+   * The trigonometric function <em>sin</em>. The sine of NaN or infinity is
+   * NaN, and the sine of 0 retains its sign. This is accurate within 1 ulp,
+   * and is semi-monotonic.
+   *
+   * @param a the angle (in radians)
+   * @return sin(a)
+   */
+  public static native double sin(double a);
+
+  /**
+   * The trigonometric function <em>cos</em>. The cosine of NaN or infinity is
+   * NaN. This is accurate within 1 ulp, and is semi-monotonic.
+   *
+   * @param a the angle (in radians)
+   * @return cos(a)
+   */
+  public static native double cos(double a);
+
+  /**
+   * The trigonometric function <em>tan</em>. The tangent of NaN or infinity
+   * is NaN, and the tangent of 0 retains its sign. This is accurate within 1
+   * ulp, and is semi-monotonic.
+   *
+   * @param a the angle (in radians)
+   * @return tan(a)
+   */
+  public static native double tan(double a);
+
+  /**
+   * The trigonometric function <em>arcsin</em>. The range of angles returned
+   * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN or
+   * its absolute value is beyond 1, the result is NaN; and the arcsine of
+   * 0 retains its sign. This is accurate within 1 ulp, and is semi-monotonic.
+   *
+   * @param a the sin to turn back into an angle
+   * @return arcsin(a)
+   */
+  public static native double asin(double a);
+
+  /**
+   * The trigonometric function <em>arccos</em>. The range of angles returned
+   * is 0 to pi radians (0 to 180 degrees). If the argument is NaN or
+   * its absolute value is beyond 1, the result is NaN. This is accurate
+   * within 1 ulp, and is semi-monotonic.
+   *
+   * @param a the cos to turn back into an angle
+   * @return arccos(a)
+   */
+  public static native double acos(double a);
+
+  /**
+   * The trigonometric function <em>arcsin</em>. The range of angles returned
+   * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN, the
+   * result is NaN; and the arctangent of 0 retains its sign. This is accurate
+   * within 1 ulp, and is semi-monotonic.
+   *
+   * @param a the tan to turn back into an angle
+   * @return arcsin(a)
+   * @see #atan2(double, double)
+   */
+  public static native double atan(double a);
+
+  /**
+   * A special version of the trigonometric function <em>arctan</em>, for
+   * converting rectangular coordinates <em>(x, y)</em> to polar
+   * <em>(r, theta)</em>. This computes the arctangent of x/y in the range
+   * of -pi to pi radians (-180 to 180 degrees). Special cases:<ul>
+   * <li>If either argument is NaN, the result is NaN.</li>
+   * <li>If the first argument is positive zero and the second argument is
+   * positive, or the first argument is positive and finite and the second
+   * argument is positive infinity, then the result is positive zero.</li>
+   * <li>If the first argument is negative zero and the second argument is
+   * positive, or the first argument is negative and finite and the second
+   * argument is positive infinity, then the result is negative zero.</li>
+   * <li>If the first argument is positive zero and the second argument is
+   * negative, or the first argument is positive and finite and the second
+   * argument is negative infinity, then the result is the double value
+   * closest to pi.</li>
+   * <li>If the first argument is negative zero and the second argument is
+   * negative, or the first argument is negative and finite and the second
+   * argument is negative infinity, then the result is the double value
+   * closest to -pi.</li>
+   * <li>If the first argument is positive and the second argument is
+   * positive zero or negative zero, or the first argument is positive
+   * infinity and the second argument is finite, then the result is the
+   * double value closest to pi/2.</li>
+   * <li>If the first argument is negative and the second argument is
+   * positive zero or negative zero, or the first argument is negative
+   * infinity and the second argument is finite, then the result is the
+   * double value closest to -pi/2.</li>
+   * <li>If both arguments are positive infinity, then the result is the
+   * double value closest to pi/4.</li>
+   * <li>If the first argument is positive infinity and the second argument
+   * is negative infinity, then the result is the double value closest to
+   * 3*pi/4.</li>
+   * <li>If the first argument is negative infinity and the second argument
+   * is positive infinity, then the result is the double value closest to
+   * -pi/4.</li>
+   * <li>If both arguments are negative infinity, then the result is the
+   * double value closest to -3*pi/4.</li>
+   *
+   * </ul><p>This is accurate within 2 ulps, and is semi-monotonic. To get r,
+   * use sqrt(x*x+y*y).
+   *
+   * @param y the y position
+   * @param x the x position
+   * @return <em>theta</em> in the conversion of (x, y) to (r, theta)
+   * @see #atan(double)
+   */
+  public static native double atan2(double y, double x);
+
+  /**
+   * Take <em>e</em><sup>a</sup>.  The opposite of <code>log()</code>. If the
+   * argument is NaN, the result is NaN; if the argument is positive infinity,
+   * the result is positive infinity; and if the argument is negative
+   * infinity, the result is positive zero. This is accurate within 1 ulp,
+   * and is semi-monotonic.
+   *
+   * @param a the number to raise to the power
+   * @return the number raised to the power of <em>e</em>
+   * @see #log(double)
+   * @see #pow(double, double)
+   */
+  public static native double exp(double a);
+
+  /**
+   * Take ln(a) (the natural log).  The opposite of <code>exp()</code>. If the
+   * argument is NaN or negative, the result is NaN; if the argument is
+   * positive infinity, the result is positive infinity; and if the argument
+   * is either zero, the result is negative infinity. This is accurate within
+   * 1 ulp, and is semi-monotonic.
+   *
+   * <p>Note that the way to get log<sub>b</sub>(a) is to do this:
+   * <code>ln(a) / ln(b)</code>.
+   *
+   * @param a the number to take the natural log of
+   * @return the natural log of <code>a</code>
+   * @see #exp(double)
+   */
+  public static native double log(double a);
+
+  /**
+   * Take a square root. If the argument is NaN or negative, the result is
+   * NaN; if the argument is positive infinity, the result is positive
+   * infinity; and if the result is either zero, the result is the same.
+   * This is accurate within the limits of doubles.
+   *
+   * <p>For other roots, use pow(a, 1 / rootNumber).
+   *
+   * @param a the numeric argument
+   * @return the square root of the argument
+   * @see #pow(double, double)
+   */
+  public static native double sqrt(double a);
+
+  /**
+   * Raise a number to a power. Special cases:<ul>
+   * <li>If the second argument is positive or negative zero, then the result
+   * is 1.0.</li>
+   * <li>If the second argument is 1.0, then the result is the same as the
+   * first argument.</li>
+   * <li>If the second argument is NaN, then the result is NaN.</li>
+   * <li>If the first argument is NaN and the second argument is nonzero,
+   * then the result is NaN.</li>
+   * <li>If the absolute value of the first argument is greater than 1 and
+   * the second argument is positive infinity, or the absolute value of the
+   * first argument is less than 1 and the second argument is negative
+   * infinity, then the result is positive infinity.</li>
+   * <li>If the absolute value of the first argument is greater than 1 and
+   * the second argument is negative infinity, or the absolute value of the
+   * first argument is less than 1 and the second argument is positive
+   * infinity, then the result is positive zero.</li>
+   * <li>If the absolute value of the first argument equals 1 and the second
+   * argument is infinite, then the result is NaN.</li>
+   * <li>If the first argument is positive zero and the second argument is
+   * greater than zero, or the first argument is positive infinity and the
+   * second argument is less than zero, then the result is positive zero.</li>
+   * <li>If the first argument is positive zero and the second argument is
+   * less than zero, or the first argument is positive infinity and the
+   * second argument is greater than zero, then the result is positive
+   * infinity.</li>
+   * <li>If the first argument is negative zero and the second argument is
+   * greater than zero but not a finite odd integer, or the first argument is
+   * negative infinity and the second argument is less than zero but not a
+   * finite odd integer, then the result is positive zero.</li>
+   * <li>If the first argument is negative zero and the second argument is a
+   * positive finite odd integer, or the first argument is negative infinity
+   * and the second argument is a negative finite odd integer, then the result
+   * is negative zero.</li>
+   * <li>If the first argument is negative zero and the second argument is
+   * less than zero but not a finite odd integer, or the first argument is
+   * negative infinity and the second argument is greater than zero but not a
+   * finite odd integer, then the result is positive infinity.</li>
+   * <li>If the first argument is negative zero and the second argument is a
+   * negative finite odd integer, or the first argument is negative infinity
+   * and the second argument is a positive finite odd integer, then the result
+   * is negative infinity.</li>
+   * <li>If the first argument is less than zero and the second argument is a
+   * finite even integer, then the result is equal to the result of raising
+   * the absolute value of the first argument to the power of the second
+   * argument.</li>
+   * <li>If the first argument is less than zero and the second argument is a
+   * finite odd integer, then the result is equal to the negative of the
+   * result of raising the absolute value of the first argument to the power
+   * of the second argument.</li>
+   * <li>If the first argument is finite and less than zero and the second
+   * argument is finite and not an integer, then the result is NaN.</li>
+   * <li>If both arguments are integers, then the result is exactly equal to
+   * the mathematical result of raising the first argument to the power of
+   * the second argument if that result can in fact be represented exactly as
+   * a double value.</li>
+   *
+   * </ul><p>(In the foregoing descriptions, a floating-point value is
+   * considered to be an integer if and only if it is a fixed point of the
+   * method [EMAIL PROTECTED] #ceil(double)} or, equivalently, a fixed point 
of the
+   * method [EMAIL PROTECTED] #floor(double)}. A value is a fixed point of a 
one-argument
+   * method if and only if the result of applying the method to the value is
+   * equal to the value.) This is accurate within 1 ulp, and is semi-monotonic.
+   *
+   * @param a the number to raise
+   * @param b the power to raise it to
+   * @return a<sup>b</sup>
+   */
+  public static native double pow(double a, double b);
+
+  /**
+   * Get the IEEE 754 floating point remainder on two numbers. This is the
+   * value of <code>x - y * <em>n</em></code>, where <em>n</em> is the closest
+   * double to <code>x / y</code> (ties go to the even n); for a zero
+   * remainder, the sign is that of <code>x</code>. If either argument is NaN,
+   * the first argument is infinite, or the second argument is zero, the result
+   * is NaN; if x is finite but y is infinite, the result is x. This is
+   * accurate within the limits of doubles.
+   *
+   * @param x the dividend (the top half)
+   * @param y the divisor (the bottom half)
+   * @return the IEEE 754-defined floating point remainder of x/y
+   * @see #rint(double)
+   */
+  public static native double IEEEremainder(double x, double y);
+
+  /**
+   * Take the nearest integer that is that is greater than or equal to the
+   * argument. If the argument is NaN, infinite, or zero, the result is the
+   * same; if the argument is between -1 and 0, the result is negative zero.
+   * Note that <code>Math.ceil(x) == -Math.floor(-x)</code>.
+   *
+   * @param a the value to act upon
+   * @return the nearest integer &gt;= <code>a</code>
+   */
+  public static native double ceil(double a);
+
+  /**
+   * Take the nearest integer that is that is less than or equal to the
+   * argument. If the argument is NaN, infinite, or zero, the result is the
+   * same. Note that <code>Math.ceil(x) == -Math.floor(-x)</code>.
+   *
+   * @param a the value to act upon
+   * @return the nearest integer &lt;= <code>a</code>
+   */
+  public static native double floor(double a);
+
+  /**
+   * Take the nearest integer to the argument.  If it is exactly between
+   * two integers, the even integer is taken. If the argument is NaN,
+   * infinite, or zero, the result is the same.
+   *
+   * @param a the value to act upon
+   * @return the nearest integer to <code>a</code>
+   */
+  public static native double rint(double a);
+
+}

Attachment: signature.asc
Description: Digital signature

Reply via email to