diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 874a8fe16a5..f66b766baae 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2006-05-24 Tom Tromey + + PR libgcj/27731: + * java/lang/natMath.cc (cbrt, cosh, expm1, hypot, log1p, sinh, + tanh): New methods. + * java/lang/Math.java (cbrt, cosh, expm1, hypot, log1p, sinh, + tanh): Declare. + 2006-05-22 Mark Wielaard * HACKING: Update GNU Classpath import instructions. diff --git a/libjava/java/lang/Math.java b/libjava/java/lang/Math.java index 6f684809366..836b8bd8636 100644 --- a/libjava/java/lang/Math.java +++ b/libjava/java/lang/Math.java @@ -1,5 +1,5 @@ /* java.lang.Math -- common mathematical functions, native allowed - Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -648,6 +648,87 @@ public final class Math return (rads * 180) / PI; } + /** + *

+ * Take a cube root. If the argument is NaN, an infinity or + * zero, then the original value is returned. The returned result is + * within 1 ulp of the exact result. For a finite value, x, + * the cube root of -x is equal to the negation of the cube root + * of x. + *

+ *

+ * For a square root, use sqrt. For other roots, use + * pow(a, 1 / rootNumber). + *

+ * + * @param a the numeric argument + * @return the cube root of the argument + * @see #sqrt(double) + * @see #pow(double, double) + * @since 1.5 + */ + public static native double cbrt(double a); + + /** + *

+ * Returns the hyperbolic cosine of the given value. For a value, + * x, the hyperbolic cosine is (ex + + * e-x)/2 + * with e being Euler's number. The returned + * result is within 2.5 ulps of the exact result. + *

+ *

+ * If the supplied value is NaN, then the original value is + * returned. For either infinity, positive infinity is returned. + * The hyperbolic cosine of zero is 1.0. + *

+ * + * @param a the numeric argument + * @return the hyperbolic cosine of a. + * @since 1.5 + */ + public static native double cosh(double a); + + /** + *

+ * Returns ea - 1. For values close to 0, the + * result of expm1(a) + 1 tend to be much closer to the + * exact result than simply exp(x). The result is within + * 1 ulp of the exact result, and results are semi-monotonic. For finite + * inputs, the returned value is greater than or equal to -1.0. Once + * a result enters within half a ulp of this limit, the limit is returned. + *

+ *

+ * For NaN, positive infinity and zero, the original value + * is returned. Negative infinity returns a result of -1.0 (the limit). + *

+ * + * @param a the numeric argument + * @return ea - 1 + * @since 1.5 + */ + public static native double expm1(double a); + + /** + *

+ * Returns the hypotenuse, a2 + b2, + * without intermediate overflow or underflow. The returned result is + * within 1 ulp of the exact result. If one parameter is held constant, + * then the result in the other parameter is semi-monotonic. + *

+ *

+ * If either of the arguments is an infinity, then the returned result + * is positive infinity. Otherwise, if either argument is NaN, + * then NaN is returned. + *

+ * + * @param a the first parameter. + * @param b the second parameter. + * @return the hypotenuse matching the supplied parameters. + * @since 1.5 + */ + public static native double hypot(double a, double b); + /** *

* Returns the base 10 logarithm of the supplied value. The returned @@ -668,6 +749,28 @@ public final class Math */ public static native double log10(double a); + /** + *

+ * Returns the natural logarithm resulting from the sum of the argument, + * a and 1. For values close to 0, the + * result of log1p(a) tend to be much closer to the + * exact result than simply log(1.0+a). The returned + * result is within 1 ulp of the exact result, and the results are + * semi-monotonic. + *

+ *

+ * Arguments of either NaN or less than -1 return + * NaN. An argument of positive infinity or zero + * returns the original argument. Negative infinity is returned from an + * argument of -1. + *

+ * + * @param a the numeric argument. + * @return the natural logarithm of a + 1. + * @since 1.5 + */ + public static native double log1p(double a); + /** *

* Returns the sign of the argument as follows: @@ -722,6 +825,50 @@ public final class Math return a; } + /** + *

+ * Returns the hyperbolic sine of the given value. For a value, + * x, the hyperbolic sine is (ex - + * e-x)/2 + * with e being Euler's number. The returned + * result is within 2.5 ulps of the exact result. + *

+ *

+ * If the supplied value is NaN, an infinity or a zero, then the + * original value is returned. + *

+ * + * @param a the numeric argument + * @return the hyperbolic sine of a. + * @since 1.5 + */ + public static native double sinh(double a); + + /** + *

+ * Returns the hyperbolic tangent of the given value. For a value, + * x, the hyperbolic tangent is (ex - + * e-x)/(ex + e-x) + * (i.e. sinh(a)/cosh(a)) + * with e being Euler's number. The returned + * result is within 2.5 ulps of the exact result. The absolute value + * of the exact result is always less than 1. Computed results are thus + * less than or equal to 1 for finite arguments, with results within + * half a ulp of either positive or negative 1 returning the appropriate + * limit value (i.e. as if the argument was an infinity). + *

+ *

+ * If the supplied value is NaN or zero, then the original + * value is returned. Positive infinity returns +1.0 and negative infinity + * returns -1.0. + *

+ * + * @param a the numeric argument + * @return the hyperbolic tangent of a. + * @since 1.5 + */ + public static native double tanh(double a); + /** * Return the ulp for the given double argument. The ulp is the * difference between the argument and the next larger double. Note diff --git a/libjava/java/lang/natMath.cc b/libjava/java/lang/natMath.cc index bc6cf7e4b54..d86d6307da8 100644 --- a/libjava/java/lang/natMath.cc +++ b/libjava/java/lang/natMath.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2002, 2006 Free Software Foundation This file is part of libgcj. @@ -107,6 +107,41 @@ jdouble java::lang::Math::log10(jdouble x) return (jdouble)::log10((double)x); } +jdouble java::lang::Math::cbrt(jdouble x) +{ + return (jdouble)::cbrt((double)x); +} + +jdouble java::lang::Math::cosh(jdouble x) +{ + return (jdouble)::cosh((double)x); +} + +jdouble java::lang::Math::expm1(jdouble x) +{ + return (jdouble)::expm1((double)x); +} + +jdouble java::lang::Math::hypot(jdouble x, jdouble y) +{ + return (jdouble)::hypot((double)x, (double)y); +} + +jdouble java::lang::Math::log1p(jdouble x) +{ + return (jdouble)::log1p((double)x); +} + +jdouble java::lang::Math::sinh(jdouble x) +{ + return (jdouble)::sinh((double)x); +} + +jdouble java::lang::Math::tanh(jdouble x) +{ + return (jdouble)::tanh((double)x); +} + static inline int floatToIntBits (jfloat value) {