Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ default T pow(T e) {
/** {@inheritDoc} */
@Override
default T cosh() {
return (exp().add(negate().exp())).divide(2);
return (exp().add(negate().exp())).half();
}

/** {@inheritDoc} */
@Override
default T sinh() {
return (exp().subtract(negate().exp())).divide(2);
return (exp().subtract(negate().exp())).half();
}

/** {@inheritDoc} */
@Override
default T acos() {
return asin().negate().add(getPi().divide(2));
return asin().negate().add(getPi().half());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ default T pow(T e) {
/** {@inheritDoc} */
@Override
default T cosh() {
return (exp().add(negate().exp())).divide(2);
return (exp().add(negate().exp())).half();
}

/** {@inheritDoc} */
@Override
default T sinh() {
return (exp().subtract(negate().exp())).divide(2);
return (exp().subtract(negate().exp())).half();
}

/** {@inheritDoc} */
@Override
default T acos() {
return asin().negate().add(getPi().divide(2));
return asin().negate().add(getPi().half());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ default int getOrder() {
@Override
default T square() {
final S f0 = getValue();
return compose(f0.square(), f0.multiply(2));
return compose(f0.square(), f0.twice());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ public FieldUnivariateDerivative2<T> compose(final T g0, final T g1, final T g2)
@Override
public FieldUnivariateDerivative2<T> sqrt() {
final T s0 = FastMath.sqrt(f0);
final T s0twice = s0.multiply(2);
final T s0twice = s0.twice();
final T s1 = f1.divide(s0twice);
final T s2 = (f2.subtract(s1.square().multiply(2))).divide(s0twice);
final T s2 = (f2.subtract(s1.square().twice())).divide(s0twice);
return new FieldUnivariateDerivative2<>(s0, s1, s2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public SparseGradient atan2(final SparseGradient x) {
if (x.value >= 0) {

// compute atan2(y, x) = 2 atan(y / (r + x))
a = divide(r.add(x)).atan().multiply(2);
a = divide(r.add(x)).atan().twice();

} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private <T extends CalculusFieldElement<T>> T differentiateThreePoint(T[] xvals,
divide(t2.multiply(t2).subtract(t1.multiply(t2)));
final T b = x1.subtract(x0).subtract(a.multiply(t1).multiply(t1)).divide(t1);

return a.multiply(t).multiply(2).add(b);
return a.multiply(t).twice().add(b);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public <T extends CalculusFieldElement<T>> FieldPolynomialSplineFunction<T> inte
mu[0] = field.getZero();
z[0] = field.getZero();
for (int i = 1; i < n; i++) {
final T g = x[i+1].subtract(x[i - 1]).multiply(2).subtract(h[i - 1].multiply(mu[i -1]));
final T g = x[i+1].subtract(x[i - 1]).twice().subtract(h[i - 1].multiply(mu[i -1]));
mu[i] = h[i].divide(g);
z[i] = y[i + 1].multiply(h[i - 1]).
subtract(y[i].multiply(x[i + 1].subtract(x[i - 1]))).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public T value(final T xNormalized) {
checkBetweenZeroAndOneIncluded(xNormalized.getReal());

if (xNormalized.getReal() >= 0 && xNormalized.getReal() <= 0.5) {
return xNormalized.multiply(xNormalized).multiply(2.);
return xNormalized.multiply(xNormalized).twice();
}
else {
final T one = getField().getOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public T getFunctionValueAccuracy() {
public T solve(final int maxEval, final CalculusFieldUnivariateFunction<T> f,
final T min, final T max, final AllowedSolution allowedSolution)
throws MathIllegalArgumentException, NullArgumentException {
return solve(maxEval, f, min, max, min.add(max).divide(2), allowedSolution);
return solve(maxEval, f, min, max, min.add(max).half(), allowedSolution);
}

/**
Expand Down Expand Up @@ -296,7 +296,7 @@ public Interval<T> solveInterval(int maxEval,
T maxX = absXA.subtract(absXB).getReal() < 0 ? absXB : absXA;
T maxY = absYA.subtract(absYB).getReal() < 0 ? absYB : absYA;
final T xTol = absoluteAccuracy.add(relativeAccuracy.multiply(maxX));
final T midpoint = xA.add(xB.subtract(xA).divide(2));
final T midpoint = xA.add(xB.subtract(xA).half());
if (xB.subtract(xA).subtract(xTol).getReal() <= 0 ||
maxY.subtract(functionValueAccuracy).getReal() < 0 ||
xA.equals(midpoint) || xB.equals(midpoint)) {
Expand Down Expand Up @@ -349,7 +349,7 @@ public Interval<T> solveInterval(int maxEval,

if (Double.isNaN(nextX.getReal())) {
// fall back to bisection
nextX = xA.add(xB.subtract(xA).divide(2));
nextX = xA.add(xB.subtract(xA).half());
start = signChangeIndex - 1;
end = signChangeIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ public Complex atan2(Complex x) {

if (FastMath.copySign(1.0, x.real) >= 0) {
// compute atan2(y, x) = 2 atan(y / (r + x))
return divide(r.add(x)).atan().multiply(2);
return divide(r.add(x)).atan().twice();
} else {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
return divide(r.subtract(x)).atan().multiply(-2).add(FastMath.PI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ public FieldComplex<T> atan2(FieldComplex<T> x) {

if (x.real.getReal() >= 0) {
// compute atan2(y, x) = 2 atan(y / (r + x))
return divide(r.add(x)).atan().multiply(2);
return divide(r.add(x)).atan().twice();
} else {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
return divide(r.subtract(x)).atan().multiply(-2).add(x.real.getPi());
Expand Down Expand Up @@ -1458,9 +1458,9 @@ public FieldComplex<T> sqrt() {

T t = FastMath.sqrt((FastMath.abs(real).add(FastMath.hypot(real, imaginary))).multiply(0.5));
if (real.getReal() >= 0.0) {
return createComplex(t, imaginary.divide(t.multiply(2)));
return createComplex(t, imaginary.divide(t.twice()));
} else {
return createComplex(FastMath.abs(imaginary).divide(t.multiply(2)),
return createComplex(FastMath.abs(imaginary).divide(t.twice()),
FastMath.copySign(t, imaginary));
}
}
Expand Down Expand Up @@ -1553,8 +1553,8 @@ public FieldComplex<T> tan() {
return getMinusI(getPartsField());
}

final FieldSinCos<T> sc2r = FastMath.sinCos(real.multiply(2));
T imaginary2 = imaginary.multiply(2);
final FieldSinCos<T> sc2r = FastMath.sinCos(real.twice());
T imaginary2 = imaginary.twice();
T d = sc2r.cos().add(FastMath.cosh(imaginary2));

return createComplex(sc2r.sin().divide(d), FastMath.sinh(imaginary2).divide(d));
Expand Down Expand Up @@ -1603,8 +1603,8 @@ public FieldComplex<T> tanh() {
if (real.getReal() < -20.0) {
return getMinusOne(getPartsField());
}
T real2 = real.multiply(2);
final FieldSinCos<T> sc2i = FastMath.sinCos(imaginary.multiply(2));
T real2 = real.twice();
final FieldSinCos<T> sc2i = FastMath.sinCos(imaginary.twice());
T d = FastMath.cosh(real2).add(sc2i.cos());

return createComplex(FastMath.sinh(real2).divide(d), sc2i.sin().divide(d));
Expand Down
6 changes: 3 additions & 3 deletions hipparchus-core/src/main/java/org/hipparchus/dfp/Dfp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ public Dfp sqrt() {
dx = newInstance(x);
dx.sign = -1;
dx = dx.add(this.divide(x));
dx = dx.divide(2);
dx = dx.half();
ppx = px;
px = x;
x = x.add(dx);
Expand Down Expand Up @@ -2609,7 +2609,7 @@ public double toDouble() {

Dfp tempDfp = DfpMath.pow(getTwo(), exponent);
while (tempDfp.lessThan(y) || tempDfp.equals(y)) {
tempDfp = tempDfp.multiply(2);
tempDfp = tempDfp.twice();
exponent++;
}
exponent--;
Expand Down Expand Up @@ -2993,7 +2993,7 @@ public Dfp asinh() {
*/
@Override
public Dfp atanh() {
return getOne().add(this).divide(getOne().subtract(this)).log().divide(2);
return getOne().add(this).divide(getOne().subtract(this)).log().half();
}

/** {@inheritDoc} */
Expand Down
22 changes: 11 additions & 11 deletions hipparchus-core/src/main/java/org/hipparchus/dfp/DfpMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ public static Dfp log(Dfp a) {

spy[0] = a.newInstance("1.33333"); // Use spy[0] for comparison
while (spx[0].add(spx[1]).greaterThan(spy[0])) {
spx[0] = spx[0].divide(2);
spx[1] = spx[1].divide(2);
spx[0] = spx[0].half();
spx[1] = spx[1].half();
p2++;
}

Expand Down Expand Up @@ -742,7 +742,7 @@ public static Dfp sin(final Dfp a) {
boolean neg = false;

/* First reduce the argument to the range of +/- PI */
Dfp x = a.remainder(pi.multiply(2));
Dfp x = a.remainder(pi.twice());

/* if x < 0 then apply identity sin(-x) = -sin(x) */
/* This puts x in the range 0 < x < PI */
Expand All @@ -755,7 +755,7 @@ public static Dfp sin(final Dfp a) {
* 0 < x < pi/2
*/

if (x.greaterThan(pi.divide(2))) {
if (x.greaterThan(pi.half())) {
x = pi.subtract(x);
}

Expand All @@ -765,8 +765,8 @@ public static Dfp sin(final Dfp a) {
} else {
final Dfp[] c = new Dfp[2];
final Dfp[] piSplit = a.getField().getPiSplit();
c[0] = piSplit[0].divide(2).subtract(x);
c[1] = piSplit[1].divide(2);
c[0] = piSplit[0].half().subtract(x);
c[1] = piSplit[1].half();
y = cosInternal(c);
}

Expand All @@ -788,7 +788,7 @@ public static Dfp cos(Dfp a) {
boolean neg = false;

/* First reduce the argument to the range of +/- PI */
Dfp x = a.remainder(pi.multiply(2));
Dfp x = a.remainder(pi.twice());

/* if x < 0 then apply identity cos(-x) = cos(x) */
/* This puts x in the range 0 < x < PI */
Expand All @@ -800,7 +800,7 @@ public static Dfp cos(Dfp a) {
* 0 < x < pi/2
*/

if (x.greaterThan(pi.divide(2))) {
if (x.greaterThan(pi.half())) {
x = pi.subtract(x);
neg = true;
}
Expand All @@ -815,8 +815,8 @@ public static Dfp cos(Dfp a) {
} else {
final Dfp[] c = new Dfp[2];
final Dfp[] piSplit = a.getField().getPiSplit();
c[0] = piSplit[0].divide(2).subtract(x);
c[1] = piSplit[1].divide(2);
c[0] = piSplit[0].half().subtract(x);
c[1] = piSplit[1].half();
y = sinInternal(c);
}

Expand Down Expand Up @@ -924,7 +924,7 @@ public static Dfp atan(final Dfp a) {
}

if (recp) {
y = piSplit[0].divide(2).subtract(y).add(piSplit[1].divide(2));
y = piSplit[0].half().subtract(y).add(piSplit[1].half());
}

if (neg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RcFieldDuplication<T extends CalculusFieldElement<T>> extends FieldDuplica
/** {@inheritDoc} */
@Override
protected void initialMeanPoint(final T[] va) {
va[2] = va[0].add(va[1].multiply(2)).divide(3.0);
va[2] = va[0].add(va[1].twice()).divide(3.0);
}

/** {@inheritDoc} */
Expand All @@ -50,7 +50,7 @@ protected T convergenceCriterion(final T r, final T max) {
/** {@inheritDoc} */
@Override
protected void update(final int m, final T[] vaM, final T[] sqrtM, final double fourM) {
final T lambdaA = sqrtM[0].multiply(sqrtM[1]).multiply(2);
final T lambdaA = sqrtM[0].multiply(sqrtM[1]).twice();
final T lambdaB = vaM[1];
vaM[0] = vaM[0].linearCombination(0.25, vaM[0], 0.25, lambdaA, 0.25, lambdaB); // xₘ
vaM[1] = vaM[1].linearCombination(0.25, vaM[1], 0.25, lambdaA, 0.25, lambdaB); // yₘ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RjFieldDuplication<T extends CalculusFieldElement<T>> extends FieldDuplica
/** {@inheritDoc} */
@Override
protected void initialMeanPoint(final T[] va) {
va[4] = va[0].add(va[1]).add(va[2]).add(va[3].multiply(2)).divide(5.0);
va[4] = va[0].add(va[1]).add(va[2]).add(va[3].twice()).divide(5.0);
}

/** {@inheritDoc} */
Expand All @@ -69,7 +69,7 @@ protected void update(final int m, final T[] vaM, final T[] sqrtM, final double
// equation A.3 in Carlson[2000]
final T rM = sM.multiply(delta.divide(sM.multiply(sM).multiply(fourM)).add(1.0).sqrt().add(1.0));
sM = dM.multiply(rM).subtract(delta.divide(fourM * fourM)).
divide(dM.add(rM.divide(fourM)).multiply(2));
divide(dM.add(rM.divide(fourM)).twice());
}

// equation 2.19 in Carlson[1995]
Expand Down Expand Up @@ -102,8 +102,8 @@ protected T evaluate(final T[] va0, final T aM, final double fourM) {
final T xyz = bigX.multiply(bigY).multiply(bigZ);
final T e2 = bigX.multiply(bigY.add(bigZ)).add(bigY.multiply(bigZ)).
subtract(bigP.multiply(bigP).multiply(3));
final T e3 = xyz.add(bigP.multiply(2).multiply(e2.add(bigP2.multiply(2))));
final T e4 = xyz.multiply(2).add(bigP.multiply(e2.add(bigP2.multiply(3)))).multiply(bigP);
final T e3 = xyz.add(bigP.twice().multiply(e2.add(bigP2.twice())));
final T e4 = xyz.twice().add(bigP.multiply(e2.add(bigP2.multiply(3)))).multiply(bigP);
final T e5 = xyz.multiply(bigP2);

final T e2e2 = e2.multiply(e2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private T arcpq(final T x, final T deltaQP, final T deltaRQ) {
final T w = x2.subtract(1).negate().divide(deltaQP);
final T rf = CarlsonEllipticIntegral.rF(x2, x.getField().getOne(), deltaRQ.multiply(w).add(1));
final T positive = w.sqrt().multiply(rf);
return x.getReal() < 0 ? LegendreEllipticIntegral.bigK(getM()).multiply(2).subtract(positive) : positive;
return x.getReal() < 0 ? LegendreEllipticIntegral.bigK(getM()).twice().subtract(positive) : positive;
}

/** Evaluate inverse of Jacobi elliptic function pq.
Expand All @@ -425,7 +425,7 @@ private T arcpqNoDivision(final T x, final T deltaQP, final T deltaRQ) {
final T rf = CarlsonEllipticIntegral.rF(x2.multiply(deltaQP), deltaQP, deltaRQ.multiply(wDeltaQP).add(deltaQP));
final T positive = wDeltaQP.sqrt().multiply(rf);
return FastMath.copySign(1.0, x.getReal()) < 0 ?
LegendreEllipticIntegral.bigK(getM()).multiply(2).subtract(positive) :
LegendreEllipticIntegral.bigK(getM()).twice().subtract(positive) :
positive;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public FieldTheta<T> values(final T z) {

}

return new FieldTheta<>(sum1.multiply(qFourth.multiply(2)),
sum2.multiply(qFourth.multiply(2)),
sum3.multiply(2).add(1),
sum4.multiply(2).add(1));
return new FieldTheta<>(sum1.multiply(qFourth.twice()),
sum2.multiply(qFourth.twice()),
sum3.twice().add(1),
sum4.twice().add(1));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public Theta values(final Complex z) {

return new Theta(sum1.multiply(2 * qFourth),
sum2.multiply(2 * qFourth),
sum3.multiply(2).add(1),
sum4.multiply(2).add(1));
sum3.twice().add(1),
sum4.twice().add(1));

}

Expand Down
Loading
Loading