From 41c29f826daf9acd24a0ff86cd279f6c3d56d893 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 13 Oct 2011 21:58:30 +0000 Subject: [PATCH] MATH-690 Removed "sinh" and "cosh" from "MathUtils"; replaced uses with calls to equivalent in "FastMath". git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1183128 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/complex/Complex.java | 24 +++++++++---------- .../apache/commons/math/util/MathUtils.java | 22 ----------------- .../commons/math/util/MathUtilsTest.java | 24 ------------------- 3 files changed, 12 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/apache/commons/math/complex/Complex.java b/src/main/java/org/apache/commons/math/complex/Complex.java index 2677ad22f..5a2dc4072 100644 --- a/src/main/java/org/apache/commons/math/complex/Complex.java +++ b/src/main/java/org/apache/commons/math/complex/Complex.java @@ -661,8 +661,8 @@ public class Complex implements FieldElement, Serializable { return NaN; } - return createComplex(FastMath.cos(real) * MathUtils.cosh(imaginary), - -FastMath.sin(real) * MathUtils.sinh(imaginary)); + return createComplex(FastMath.cos(real) * FastMath.cosh(imaginary), + -FastMath.sin(real) * FastMath.sinh(imaginary)); } /** @@ -701,8 +701,8 @@ public class Complex implements FieldElement, Serializable { return NaN; } - return createComplex(MathUtils.cosh(real) * FastMath.cos(imaginary), - MathUtils.sinh(real) * FastMath.sin(imaginary)); + return createComplex(FastMath.cosh(real) * FastMath.cos(imaginary), + FastMath.sinh(real) * FastMath.sin(imaginary)); } /** @@ -865,8 +865,8 @@ public class Complex implements FieldElement, Serializable { return NaN; } - return createComplex(FastMath.sin(real) * MathUtils.cosh(imaginary), - FastMath.cos(real) * MathUtils.sinh(imaginary)); + return createComplex(FastMath.sin(real) * FastMath.cosh(imaginary), + FastMath.cos(real) * FastMath.sinh(imaginary)); } /** @@ -905,8 +905,8 @@ public class Complex implements FieldElement, Serializable { return NaN; } - return createComplex(MathUtils.sinh(real) * FastMath.cos(imaginary), - MathUtils.cosh(real) * FastMath.sin(imaginary)); + return createComplex(FastMath.sinh(real) * FastMath.cos(imaginary), + FastMath.cosh(real) * FastMath.sin(imaginary)); } /** @@ -1021,10 +1021,10 @@ public class Complex implements FieldElement, Serializable { double real2 = 2.0 * real; double imaginary2 = 2.0 * imaginary; - double d = FastMath.cos(real2) + MathUtils.cosh(imaginary2); + double d = FastMath.cos(real2) + FastMath.cosh(imaginary2); return createComplex(FastMath.sin(real2) / d, - MathUtils.sinh(imaginary2) / d); + FastMath.sinh(imaginary2) / d); } /** @@ -1066,9 +1066,9 @@ public class Complex implements FieldElement, Serializable { double real2 = 2.0 * real; double imaginary2 = 2.0 * imaginary; - double d = MathUtils.cosh(real2) + FastMath.cos(imaginary2); + double d = FastMath.cosh(real2) + FastMath.cos(imaginary2); - return createComplex(MathUtils.sinh(real2) / d, + return createComplex(FastMath.sinh(real2) / d, FastMath.sin(imaginary2) / d); } diff --git a/src/main/java/org/apache/commons/math/util/MathUtils.java b/src/main/java/org/apache/commons/math/util/MathUtils.java index 0145c25fd..bfafe3563 100644 --- a/src/main/java/org/apache/commons/math/util/MathUtils.java +++ b/src/main/java/org/apache/commons/math/util/MathUtils.java @@ -75,17 +75,6 @@ public final class MathUtils { super(); } - /** - * Returns the - * hyperbolic cosine of x. - * - * @param x double value for which to find the hyperbolic cosine - * @return hyperbolic cosine of x - */ - public static double cosh(double x) { - return (FastMath.exp(x) + FastMath.exp(-x)) / 2.0; - } - /** * Returns an integer hash code representing the given double value. * @@ -505,17 +494,6 @@ public final class MathUtils { return (x == ZS) ? ZS : (x > ZS) ? PS : NS; } - /** - * Compute the - * hyperbolic sine of the argument. - * - * @param x Value for which to find the hyperbolic sine. - * @return hyperbolic sine of {@code x}. - */ - public static double sinh(double x) { - return (FastMath.exp(x) - FastMath.exp(-x)) / 2.0; - } - /** * Raise an int to an int power. * diff --git a/src/test/java/org/apache/commons/math/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math/util/MathUtilsTest.java index 6a3ddfd9f..ef129caee 100644 --- a/src/test/java/org/apache/commons/math/util/MathUtilsTest.java +++ b/src/test/java/org/apache/commons/math/util/MathUtilsTest.java @@ -33,18 +33,6 @@ import org.junit.Test; * 2007) $ */ public final class MathUtilsTest { - @Test - public void testCosh() { - double x = 3.0; - double expected = 10.06766; - Assert.assertEquals(expected, MathUtils.cosh(x), 1.0e-5); - } - - @Test - public void testCoshNaN() { - Assert.assertTrue(Double.isNaN(MathUtils.cosh(Double.NaN))); - } - @Test public void testHash() { double[] testArray = { @@ -505,18 +493,6 @@ public final class MathUtilsTest { Assert.assertEquals((short) (-1), MathUtils.sign((short) (-2))); } - @Test - public void testSinh() { - double x = 3.0; - double expected = 10.01787; - Assert.assertEquals(expected, MathUtils.sinh(x), 1.0e-5); - } - - @Test - public void testSinhNaN() { - Assert.assertTrue(Double.isNaN(MathUtils.sinh(Double.NaN))); - } - @Test public void testPow() {