From cf1a5c59ddbab69b940d19ef1c9c9dbd4610fd8b Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Fri, 8 Nov 2013 19:08:22 +0000 Subject: [PATCH] [MATH-1059] Replace Math with FastMath. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1540155 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math3/complex/Complex.java | 18 ++++++++--------- .../math3/analysis/FunctionUtilsTest.java | 20 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/complex/Complex.java b/src/main/java/org/apache/commons/math3/complex/Complex.java index ac8185b17..cdcddf278 100644 --- a/src/main/java/org/apache/commons/math3/complex/Complex.java +++ b/src/main/java/org/apache/commons/math3/complex/Complex.java @@ -634,7 +634,7 @@ public class Complex implements FieldElement, Serializable { * * * where the (real) functions on the right-hand side are - * {@link java.lang.Math#sin}, {@link java.lang.Math#cos}, + * {@link FastMath#sin}, {@link FastMath#cos}, * {@link FastMath#cosh} and {@link FastMath#sinh}. *
* Returns {@link Complex#NaN} if either real or imaginary part of the @@ -674,7 +674,7 @@ public class Complex implements FieldElement, Serializable { * * * where the (real) functions on the right-hand side are - * {@link java.lang.Math#sin}, {@link java.lang.Math#cos}, + * {@link FastMath#sin}, {@link FastMath#cos}, * {@link FastMath#cosh} and {@link FastMath#sinh}. *
* Returns {@link Complex#NaN} if either real or imaginary part of the @@ -714,8 +714,8 @@ public class Complex implements FieldElement, Serializable { * * * where the (real) functions on the right-hand side are - * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and - * {@link java.lang.Math#sin}. + * {@link FastMath#exp}, {@link FastMath#cos}, and + * {@link FastMath#sin}. *
* Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. @@ -755,9 +755,9 @@ public class Complex implements FieldElement, Serializable { * log(a + bi) = ln(|a + bi|) + arg(a + bi)i * * - * where ln on the right hand side is {@link java.lang.Math#log}, + * where ln on the right hand side is {@link FastMath#log}, * {@code |a + bi|} is the modulus, {@link Complex#abs}, and - * {@code arg(a + bi) = }{@link java.lang.Math#atan2}(b, a). + * {@code arg(a + bi) = }{@link FastMath#atan2}(b, a). *
* Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. @@ -838,7 +838,7 @@ public class Complex implements FieldElement, Serializable { * * * where the (real) functions on the right-hand side are - * {@link java.lang.Math#sin}, {@link java.lang.Math#cos}, + * {@link FastMath#sin}, {@link FastMath#cos}, * {@link FastMath#cosh} and {@link FastMath#sinh}. *
* Returns {@link Complex#NaN} if either real or imaginary part of the @@ -878,7 +878,7 @@ public class Complex implements FieldElement, Serializable { * * * where the (real) functions on the right-hand side are - * {@link java.lang.Math#sin}, {@link java.lang.Math#cos}, + * {@link FastMath#sin}, {@link FastMath#cos}, * {@link FastMath#cosh} and {@link FastMath#sinh}. *
* Returns {@link Complex#NaN} if either real or imaginary part of the @@ -917,7 +917,7 @@ public class Complex implements FieldElement, Serializable { * else return {@code |b|/2t + sign(b)t i } * * where
    - *
  • {@code |a| = }{@link Math#abs}(a)
  • + *
  • {@code |a| = }{@link FastMath#abs}(a)
  • *
  • {@code |a + bi| = }{@link Complex#abs}(a + bi)
  • *
  • {@code sign(b) = }{@link FastMath#copySign(double,double) copySign(1d, b)} *
diff --git a/src/test/java/org/apache/commons/math3/analysis/FunctionUtilsTest.java b/src/test/java/org/apache/commons/math3/analysis/FunctionUtilsTest.java index f9bf3e8a6..5e2bc968f 100644 --- a/src/test/java/org/apache/commons/math3/analysis/FunctionUtilsTest.java +++ b/src/test/java/org/apache/commons/math3/analysis/FunctionUtilsTest.java @@ -46,7 +46,7 @@ import org.junit.Test; * Test for {@link FunctionUtils}. */ public class FunctionUtilsTest { - private final double EPS = Math.ulp(1d); + private final double EPS = FastMath.ulp(1d); @Test public void testCompose() { @@ -113,7 +113,7 @@ public class FunctionUtilsTest { UnivariateDifferentiableFunction inv = new Inverse(); final double a = 123.456; - Assert.assertEquals(- 1 / (a * a) -1 + Math.cos(a), + Assert.assertEquals(- 1 / (a * a) -1 + FastMath.cos(a), FunctionUtils.add(inv, m, c, sin).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS); } @@ -138,11 +138,11 @@ public class FunctionUtilsTest { UnivariateDifferentiableFunction inv = new Inverse(); UnivariateDifferentiableFunction pow = new Power(2.5); UnivariateDifferentiableFunction cos = new Cos(); - Assert.assertEquals(1.5 * Math.sqrt(a) * Math.cos(a) - Math.pow(a, 1.5) * Math.sin(a), + Assert.assertEquals(1.5 * FastMath.sqrt(a) * FastMath.cos(a) - FastMath.pow(a, 1.5) * FastMath.sin(a), FunctionUtils.multiply(inv, pow, cos).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), EPS); UnivariateDifferentiableFunction cosh = new Cosh(); - Assert.assertEquals(1.5 * Math.sqrt(a) * Math.cosh(a) + Math.pow(a, 1.5) * Math.sinh(a), + Assert.assertEquals(1.5 * FastMath.sqrt(a) * FastMath.cosh(a) + FastMath.pow(a, 1.5) * FastMath.sinh(a), FunctionUtils.multiply(inv, pow, cosh).value(new DerivativeStructure(1, 1, 0, a)).getPartialDerivative(1), 8 * EPS); } @@ -188,7 +188,7 @@ public class FunctionUtilsTest { UnivariateFunction sinc2 = new Sinc(); for (int i = 0; i < 10; i++) { - double x = Math.random(); + double x = FastMath.random(); Assert.assertEquals(sinc1.value(x), sinc2.value(x), EPS); } } @@ -202,31 +202,31 @@ public class FunctionUtilsTest { UnivariateFunction pow2 = FunctionUtils.fix2ndArgument(new Pow(), 2); for (int i = 0; i < 10; i++) { - double x = Math.random() * 10; + double x = FastMath.random() * 10; Assert.assertEquals(pow1.value(x), pow2.value(x), 0); } } @Test(expected = NumberIsTooLargeException.class) public void testSampleWrongBounds(){ - FunctionUtils.sample(new Sin(), Math.PI, 0.0, 10); + FunctionUtils.sample(new Sin(), FastMath.PI, 0.0, 10); } @Test(expected = NotStrictlyPositiveException.class) public void testSampleNegativeNumberOfPoints(){ - FunctionUtils.sample(new Sin(), 0.0, Math.PI, -1); + FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, -1); } @Test(expected = NotStrictlyPositiveException.class) public void testSampleNullNumberOfPoints(){ - FunctionUtils.sample(new Sin(), 0.0, Math.PI, 0); + FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, 0); } @Test public void testSample() { final int n = 11; final double min = 0.0; - final double max = Math.PI; + final double max = FastMath.PI; final double[] actual = FunctionUtils.sample(new Sin(), min, max, n); for (int i = 0; i < n; i++) { final double x = min + (max - min) / n * i;