You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/09/12 13:30:56 UTC
svn commit: r442564 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/lang/ main/native/luni/linux/ main/native/luni/shared/
main/native/luni/windows/ test/java/org/apache/harmony/luni/tests/java/lang/
Author: pyang
Date: Tue Sep 12 04:30:55 2006
New Revision: 442564
URL: http://svn.apache.org/viewvc?view=rev&rev=442564
Log:
Patch applied for HARMONY-1438 with minor changes([class][luni] new methods java.lang.Math.ulp(double), java.lang.Math.ulp(float),java.lang.StrictMath.ulp(double), java.lang.StrictMath.ulp(float))
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/math.c
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java Tue Sep 12 04:30:55 2006
@@ -458,7 +458,7 @@
// check for NaN
if (d != d)
return 0L;
- return (long) Math.floor(d + 0.5d);
+ return (long) floor(d + 0.5d);
}
/**
@@ -472,7 +472,7 @@
// check for NaN
if (f != f)
return 0;
- return (int) Math.floor(f + 0.5f);
+ return (int) floor(f + 0.5f);
}
/**
@@ -558,4 +558,50 @@
public static double toDegrees(double angrad) {
return angrad * 180d / PI;
}
+
+ /**
+ * Answers the argument's ulp. The size of a ulp of a double value is the
+ * positive distance between this value and the double value next larger
+ * in magnitude. For non-NaN x, ulp(-x) == ulp(x).
+ *
+ * @param d
+ * the floating-point value to compute ulp of
+ * @return the size of a ulp of the argument.
+ */
+ public static double ulp(double d) {
+ // special cases
+ if (Double.isInfinite(d)) {
+ return Double.POSITIVE_INFINITY;
+ } else if (d == Double.MAX_VALUE || d == -Double.MAX_VALUE) {
+ return pow(2, 971);
+ }
+ d = abs(d);
+ return nextafter(d, Double.MAX_VALUE) - d;
+ }
+
+ /**
+ * Answers the argument's ulp. The size of a ulp of a float value is the
+ * positive distance between this value and the float value next larger
+ * in magnitude. For non-NaN x, ulp(-x) == ulp(x).
+ *
+ * @param f
+ * the floating-point value to compute ulp of
+ * @return the size of a ulp of the argument.
+ */
+ public static float ulp(float f) {
+ // special cases
+ if (Float.isNaN(f)) {
+ return Float.NaN;
+ } else if (Float.isInfinite(f)) {
+ return Float.POSITIVE_INFINITY;
+ } else if (f == Float.MAX_VALUE || f == -Float.MAX_VALUE) {
+ return (float) pow(2, 104);
+ }
+ f = abs(f);
+ return nextafterf(f, Float.MAX_VALUE) - f;
+ }
+
+ private native static double nextafter(double x, double y);
+
+ private native static float nextafterf(float x, float y);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java Tue Sep 12 04:30:55 2006
@@ -548,4 +548,50 @@
public static double toRadians(double angdeg) {
return angdeg / 180d * PI;
}
+
+ /**
+ * Answers the argument's ulp. The size of a ulp of a double value is the
+ * positive distance between this value and the double value next larger
+ * in magnitude. For non-NaN x, ulp(-x) == ulp(x).
+ *
+ * @param d
+ * the floating-point value to compute ulp of
+ * @return the size of a ulp of the argument.
+ */
+ public static double ulp(double d) {
+ // special cases
+ if (Double.isInfinite(d)) {
+ return Double.POSITIVE_INFINITY;
+ } else if (d == Double.MAX_VALUE || d == -Double.MAX_VALUE) {
+ return pow(2, 971);
+ }
+ d = Math.abs(d);
+ return nextafter(d, Double.MAX_VALUE) - d;
+ }
+
+ /**
+ * Answers the argument's ulp. The size of a ulp of a float value is the
+ * positive distance between this value and the float value next larger
+ * in magnitude. For non-NaN x, ulp(-x) == ulp(x).
+ *
+ * @param f
+ * the floating-point value to compute ulp of
+ * @return the size of a ulp of the argument.
+ */
+ public static float ulp(float f) {
+ // special cases
+ if (Float.isNaN(f)) {
+ return Float.NaN;
+ } else if (Float.isInfinite(f)) {
+ return Float.POSITIVE_INFINITY;
+ } else if (f == Float.MAX_VALUE || f == -Float.MAX_VALUE) {
+ return (float) pow(2, 104);
+ }
+ f = Math.abs(f);
+ return nextafterf(f, Float.MAX_VALUE) - f;
+ }
+
+ private native static double nextafter(double x, double y);
+
+ private native static float nextafterf(float x, float y);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp Tue Sep 12 04:30:55 2006
@@ -105,6 +105,8 @@
Java_java_lang_Math_IEEEremainder;
Java_java_lang_Math_log;
Java_java_lang_Math_log1p;
+ Java_java_lang_Math_nextafter;
+ Java_java_lang_Math_nextafterf;
Java_java_lang_Math_pow;
Java_java_lang_Math_rint;
Java_java_lang_Math_sin;
@@ -129,6 +131,8 @@
Java_java_lang_StrictMath_log;
Java_java_lang_StrictMath_log10;
Java_java_lang_StrictMath_log1p;
+ Java_java_lang_StrictMath_nextafter;
+ Java_java_lang_StrictMath_nextafterf;
Java_java_lang_StrictMath_pow;
Java_java_lang_StrictMath_rint;
Java_java_lang_StrictMath_sin;
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/math.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/math.c?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/math.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/math.c Tue Sep 12 04:30:55 2006
@@ -44,6 +44,8 @@
jdouble internal_hypot(jdouble arg1, jdouble arg2);
jdouble internal_log1p(jdouble arg1);
jdouble internal_log10(jdouble arg1);
+jdouble internal_nextafter(jdouble arg1,jdouble arg2);
+jfloat internal_nextafterf(jfloat arg1,jfloat arg2);
extern scaleUpDouble (double *, int);
@@ -52,7 +54,7 @@
{
jdouble result;
- result = fdlibm_acos (arg1);
+ result = acos (arg1);
return result;
}
@@ -74,7 +76,7 @@
{
jdouble result;
- result = fdlibm_asin (arg1);
+ result = asin (arg1);
return result;
}
@@ -84,7 +86,7 @@
{
jdouble result;
- result = fdlibm_atan (arg1);
+ result = atan (arg1);
return result;
}
@@ -94,7 +96,7 @@
{
jdouble result;
- result = fdlibm_atan2 (arg1, arg2);
+ result = atan2 (arg1, arg2);
return result;
}
@@ -104,7 +106,7 @@
{
jdouble result;
- result = fdlibm_cbrt (arg1);
+ result = cbrt (arg1);
return result;
}
@@ -114,7 +116,7 @@
{
jdouble result;
- result = fdlibm_ceil (arg1);
+ result = ceil (arg1);
return result;
}
@@ -124,7 +126,7 @@
{
jdouble result;
- result = fdlibm_cos (arg1);
+ result = cos (arg1);
return result;
}
@@ -134,7 +136,7 @@
{
jdouble result;
- result = fdlibm_cosh (arg1);
+ result = cosh (arg1);
return result;
}
@@ -144,7 +146,7 @@
{
jdouble result;
- result = fdlibm_exp (arg1);
+ result = exp (arg1);
return result;
}
@@ -154,7 +156,7 @@
{
jdouble result;
- result = fdlibm_expm1 (arg1);
+ result = expm1 (arg1);
return result;
}
@@ -164,7 +166,7 @@
{
jdouble result;
- result = fdlibm_floor (arg1);
+ result = floor (arg1);
return result;
}
@@ -174,7 +176,7 @@
{
jdouble result;
- result = fdlibm_hypot (arg1, arg2);
+ result = hypot (arg1, arg2);
return result;
}
@@ -184,7 +186,7 @@
{
jdouble result;
- result = fdlibm_remainder (arg1, arg2);
+ result = remainder (arg1, arg2);
return result;
}
@@ -194,7 +196,7 @@
{
jdouble result;
- result = fdlibm_log (arg1);
+ result = log (arg1);
return result;
}
@@ -204,7 +206,7 @@
{
jdouble result;
- result = fdlibm_log10 (arg1);
+ result = log10 (arg1);
return result;
}
@@ -214,17 +216,49 @@
{
jdouble result;
- result = fdlibm_log1p (arg1);
+ result = log1p (arg1);
return result;
}
jdouble
+internal_nextafter(jdouble arg1,jdouble arg2){
+ jdouble result;
+
+ result = nextafter (arg1,arg2);
+
+ return result;
+}
+
+/*
+ * Please note: this method is just for Float.ulp() use, not necessarilly
+ * has same behavior with nextafter(double, double)
+ */
+jfloat
+internal_nextafterf(jfloat arg1,jfloat arg2){
+ jint hx = *(jint*)&arg1;
+ jint hy = *(jint*)&arg2;
+
+ if (!(hx&0x7fffffff)){ /* arg1 == 0 */
+ *(jint*)&arg1 = (hy & 0x80000000) | 0x1;
+ return arg1;
+ }
+
+ if((hx > 0) ^ (hx > hy)){ /* |arg1| < |arg2| */
+ hx += 1;
+ }else{
+ hx -= 1;
+ }
+ *(jint*)&arg1 = hx;
+ return arg1;
+}
+
+jdouble
internal_pow (jdouble arg1, jdouble arg2)
{
jdouble result;
- result = fdlibm_pow (arg1, arg2);
+ result = pow (arg1, arg2);
return result;
}
@@ -234,7 +268,7 @@
{
jdouble result;
- result = fdlibm_rint (arg1);
+ result = rint (arg1);
return result;
}
@@ -244,7 +278,7 @@
{
jdouble result;
- result = fdlibm_sin (arg1);
+ result = sin (arg1);
return result;
}
@@ -254,7 +288,7 @@
{
jdouble result;
- result = fdlibm_sinh (arg1);
+ result = sinh (arg1);
return result;
}
@@ -264,7 +298,7 @@
{
jdouble result;
- result = fdlibm_sqrt (arg1);
+ result = sqrt (arg1);
return result;
}
@@ -274,7 +308,7 @@
{
jdouble result;
- result = fdlibm_tan (arg1);
+ result = tan (arg1);
return result;
}
@@ -284,7 +318,7 @@
{
jdouble result;
- result = fdlibm_tanh (arg1);
+ result = tanh (arg1);
return result;
}
@@ -471,6 +505,29 @@
return internal_log1p (arg1);
}
+jdouble JNICALL
+Java_java_lang_StrictMath_nextafter (JNIEnv * env, jclass jclazz, jdouble arg1, jdouble arg2)
+{
+ return internal_nextafter(arg1, arg2);
+}
+
+jdouble JNICALL
+Java_java_lang_Math_nextafter (JNIEnv * env, jclass jclazz, jdouble arg1, jdouble arg2)
+{
+ return internal_nextafter(arg1, arg2);
+}
+
+jfloat JNICALL
+Java_java_lang_StrictMath_nextafterf (JNIEnv * env, jclass jclazz, jfloat arg1, jfloat arg2)
+{
+ return internal_nextafterf(arg1, arg2);
+}
+
+jfloat JNICALL
+Java_java_lang_Math_nextafterf (JNIEnv * env, jclass jclazz, jfloat arg1, jfloat arg2)
+{
+ return internal_nextafterf(arg1, arg2);
+}
jdouble JNICALL
Java_java_lang_StrictMath_pow (JNIEnv * env, jclass jclazz, jdouble arg1,
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def Tue Sep 12 04:30:55 2006
@@ -98,6 +98,8 @@
Java_java_lang_Math_IEEEremainder
Java_java_lang_Math_log
Java_java_lang_Math_log1p
+ Java_java_lang_Math_nextafter
+ Java_java_lang_Math_nextafterf
Java_java_lang_Math_pow
Java_java_lang_Math_rint
Java_java_lang_Math_sin
@@ -122,6 +124,8 @@
Java_java_lang_StrictMath_log
Java_java_lang_StrictMath_log10
Java_java_lang_StrictMath_log1p
+ Java_java_lang_StrictMath_nextafter
+ Java_java_lang_StrictMath_nextafterf
Java_java_lang_StrictMath_pow
Java_java_lang_StrictMath_rint
Java_java_lang_StrictMath_sin
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java Tue Sep 12 04:30:55 2006
@@ -607,4 +607,91 @@
converted >= d * 0.99999999 && converted <= d * 1.00000001);
}
}
+
+ /**
+ * @tests java.lang.Math#ulp(double)
+ */
+ @SuppressWarnings("boxing")
+ public void test_ulp_D() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN)));
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
+ .ulp(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
+ .ulp(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(+0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(-0.0), 0D);
+ assertEquals("Returned incorrect value", Math.pow(2, 971), Math
+ .ulp(Double.MAX_VALUE), 0D);
+ assertEquals("Returned incorrect value", Math.pow(2, 971), Math
+ .ulp(-Double.MAX_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(Double.MIN_VALUE), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(-Double.MIN_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
+ .ulp(1.0), 0D);
+ assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
+ .ulp(-1.0), 0D);
+ assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math
+ .ulp(1153.0), 0D);
+ }
+
+ /**
+ * @tests java.lang.Math#ulp(float)
+ */
+ @SuppressWarnings("boxing")
+ public void test_ulp_f() {
+ // Test for special cases
+ assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN)));
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
+ .ulp(Float.POSITIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
+ .ulp(Float.NEGATIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(+0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(-0.0f), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, Math
+ .ulp(Float.MAX_VALUE), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, Math
+ .ulp(-Float.MAX_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.4E-45f, Math
+ .ulp(Float.MIN_VALUE), 0f);
+ assertEquals("Returned incorrect value", 1.4E-45f, Math
+ .ulp(-Float.MIN_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f),
+ 0f);
+ assertEquals("Returned incorrect value", 1.1920929E-7f,
+ Math.ulp(-1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.2207031E-4f, Math
+ .ulp(1153.0f), 0f);
+ assertEquals("Returned incorrect value", 5.6E-45f, Math
+ .ulp(9.403954E-38f), 0f);
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java?view=diff&rev=442564&r1=442563&r2=442564
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java Tue Sep 12 04:30:55 2006
@@ -280,10 +280,10 @@
assertEquals("Should return POSITIVE_INFINITY",
Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
Double.POSITIVE_INFINITY));
- assertEquals("Should return NaN", Double.NaN, StrictMath.hypot(Double.NaN,
- 2342301.89843));
- assertEquals("Should return NaN", Double.NaN, StrictMath.hypot(-345.2680,
- Double.NaN));
+ assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(Double.NaN,
+ 2342301.89843)));
+ assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(-345.2680,
+ Double.NaN)));
assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath
.hypot(12322.12, -2396393.2258));
@@ -662,4 +662,92 @@
converted >= d * 0.99999999 && converted <= d * 1.00000001);
}
}
+
+ /**
+ * @tests java.lang.StrictMath#ulp(double)
+ */
+ @SuppressWarnings("boxing")
+ public void test_ulp_D() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double
+ .isNaN(StrictMath.ulp(Double.NaN)));
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
+ StrictMath.ulp(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
+ StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(+0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(-0.0), 0D);
+ assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
+ StrictMath.ulp(Double.MAX_VALUE), 0D);
+ assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
+ StrictMath.ulp(-Double.MAX_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(Double.MIN_VALUE), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(-Double.MIN_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", 2.220446049250313E-16,
+ StrictMath.ulp(1.0), 0D);
+ assertEquals("Returned incorrect value", 2.220446049250313E-16,
+ StrictMath.ulp(-1.0), 0D);
+ assertEquals("Returned incorrect value", 2.2737367544323206E-13,
+ StrictMath.ulp(1153.0), 0D);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#ulp(float)
+ */
+ @SuppressWarnings("boxing")
+ public void test_ulp_f() {
+ // Test for special cases
+ assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN)));
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
+ StrictMath.ulp(Float.POSITIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
+ StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(+0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(-0.0f), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
+ .ulp(Float.MAX_VALUE), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
+ .ulp(-Float.MAX_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
+ .ulp(Float.MIN_VALUE), 0f);
+ assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
+ .ulp(-Float.MIN_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
+ .ulp(1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
+ .ulp(-1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath
+ .ulp(1153.0f), 0f);
+ assertEquals("Returned incorrect value", 5.6E-45f, Math
+ .ulp(9.403954E-38f), 0f);
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+
}