From abd91e389e4462208eb004b38d378f67d9676ec1 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 29 Mar 2010 15:20:01 -0700 Subject: Fix build. Rather than try to be clever with header files (which didn't work with glibc for the sim build) let's make Math.copySign have the StrictMath behavior, and have StrictMath call Math. (The other way round, though it might seem more logical, wouldn't solve the problem. We already have numerous cases of StrictMath calling Math anyway.) Change-Id: Ifff065ddc8fbd5d5f8d4d5b67bc9ac07a719eb00 --- luni/src/main/java/java/lang/StrictMath.java | 8 ++++++-- luni/src/main/native/java_lang_Math.c | 6 ++++-- luni/src/main/native/java_lang_StrictMath.c | 12 ------------ 3 files changed, 10 insertions(+), 16 deletions(-) (limited to 'luni') diff --git a/luni/src/main/java/java/lang/StrictMath.java b/luni/src/main/java/java/lang/StrictMath.java index cd3c9b5..5c6ebc7 100644 --- a/luni/src/main/java/java/lang/StrictMath.java +++ b/luni/src/main/java/java/lang/StrictMath.java @@ -1042,7 +1042,9 @@ public final class StrictMath { * @since 1.6 * @hide */ - public static native double copySign(double magnitude, double sign); + public static double copySign(double magnitude, double sign) { + return Math.copySign(magnitude, sign); + } /** * Returns a float with the given magnitude and the sign of {@code sign}. @@ -1050,7 +1052,9 @@ public final class StrictMath { * @since 1.6 * @hide */ - public static native float copySign(float magnitude, float sign); + public static float copySign(float magnitude, float sign) { + return Math.copySign(magnitude, sign); + } /** * Answers the exponent of a float. diff --git a/luni/src/main/native/java_lang_Math.c b/luni/src/main/native/java_lang_Math.c index 35754cd..90cb9b5 100644 --- a/luni/src/main/native/java_lang_Math.c +++ b/luni/src/main/native/java_lang_Math.c @@ -160,11 +160,13 @@ static jfloat jnextafterf(JNIEnv* env, jclass clazz, jfloat a, jfloat b) } static jdouble copySign(JNIEnv* env, jclass clazz, jdouble a, jdouble b) { - return copysign(a, b); + // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive. + return copysign(a, isnan(b) ? 1.0 : b); } static jfloat copySign_f(JNIEnv* env, jclass clazz, jfloat a, jfloat b) { - return copysignf(a, b); + // Our StrictMath.copySign delegates to Math.copySign, so we need to treat NaN as positive. + return copysignf(a, isnan(b) ? 1.0 : b); } /* diff --git a/luni/src/main/native/java_lang_StrictMath.c b/luni/src/main/native/java_lang_StrictMath.c index 3839c21..cb0f87e 100644 --- a/luni/src/main/native/java_lang_StrictMath.c +++ b/luni/src/main/native/java_lang_StrictMath.c @@ -20,8 +20,6 @@ #include "../../external/fdlibm/fdlibm.h" _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_; -#include - /* native public static double sin(double a); */ static jdouble jsin(JNIEnv* env, jclass clazz, jdouble a) { @@ -186,14 +184,6 @@ static jfloat jnextafterf(JNIEnv* env, jclass clazz, jfloat arg1, jfloat arg2) return arg1; } -static jdouble copySign(JNIEnv* env, jclass clazz, jdouble a, jdouble b) { - return copysign(a, isnan(b) ? 1.0 : b); -} - -static jfloat copySign_f(JNIEnv* env, jclass clazz, jfloat a, jfloat b) { - return copysignf(a, isnan(b) ? 1.0f : b); -} - /* * JNI registration. */ @@ -206,8 +196,6 @@ static JNINativeMethod gMethods[] = { { "atan2", "(DD)D", jatan2 }, { "cbrt", "(D)D", jcbrt }, { "ceil", "(D)D", jceil }, - { "copySign", "(DD)D", copySign }, - { "copySign", "(FF)F", copySign_f }, { "cos", "(D)D", jcos }, { "cosh", "(D)D", jcosh }, { "exp", "(D)D", jexp }, -- cgit v1.1