Java Code Examples for org.apache.commons.math3.util.ArithmeticUtils#pow()

The following examples show how to use org.apache.commons.math3.util.ArithmeticUtils#pow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * CombinatoricsUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 2
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * ArithmeticUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 3
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * ArithmeticUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 4
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * ArithmeticUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 5
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * CombinatoricsUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 6
Source File: DerivativeStructureTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReciprocal() {
    for (double x = 0.1; x < 1.2; x += 0.1) {
        DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
        Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
        for (int i = 1; i < r.getOrder(); ++i) {
            double expected = ArithmeticUtils.pow(-1, i) * CombinatoricsUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
Example 7
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 8
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 9
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 10
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 11
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 12
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 13
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 14
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 15
Source File: BigFraction.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 16
Source File: BigFraction_s.java    From coming with MIT License 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 17
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 18
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final long exponent) {
    if (exponent < 0) {
        return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 19
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
Example 20
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>
 * Returns a <code>BigFraction</code> whose value is
 * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
 * </p>
 *
 * @param exponent
 *            exponent to which this <code>BigFraction</code> is to be raised.
 * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
 */
public BigFraction pow(final BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0) {
        final BigInteger eNeg = exponent.negate();
        return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
                               ArithmeticUtils.pow(numerator,   eNeg));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}