Skip to content

Commit

Permalink
Merge branch 'signum'
Browse files Browse the repository at this point in the history
  • Loading branch information
maisonobe committed Jun 11, 2021
2 parents e0756c4 + c81a6a5 commit 2b59ff3
Show file tree
Hide file tree
Showing 85 changed files with 1,848 additions and 385 deletions.
5 changes: 4 additions & 1 deletion hipparchus-core/src/changes/changes.xml
Expand Up @@ -50,12 +50,15 @@ If the output is not quite correct, check for invisible trailing spaces!
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="issues/138">
Renamed signum into sign in field classes, and improved implementation for complex numbers.
</action>
<action dev="bryan" type="fix" issue="issues/131">
Fixed consistent implementations between {Field}LUDecomposition classes.
</action>
<action dev="luc" type="add">
Added Carlson elliptic integrals (R_F, R_J, R_G, R_D, and R_C)
both for Complex and FieldComplex.
both for real, CalculusFieldElement, Complex, and FieldComplex.
</action>
<action dev="luc" type="fix" issue="issues/129">
Fixed branch cut on imaginary axis for complex atan.
Expand Down
Expand Up @@ -412,11 +412,13 @@ T linearCombination(double[] a, T[] b)
*/
T remainder(T a);

/** Compute the signum of the instance.
* The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise
/** Compute the sign of the instance.
* The sign is -1 for negative numbers, +1 for positive numbers and 0 otherwise,
* for Complex number, it is extended on the unit circle (equivalent to z/|z|,
* with special handling for 0 and NaN)
* @return -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
*/
T signum();
T sign();

/**
* Returns the instance with the sign of the argument.
Expand Down
Expand Up @@ -328,7 +328,7 @@ public DerivativeStructure rint() {
/** {@inheritDoc}
*/
@Override
public DerivativeStructure signum() {
public DerivativeStructure sign() {
return factory.constant(FastMath.signum(data[0]));
}

Expand Down
Expand Up @@ -359,8 +359,8 @@ public FieldDerivativeStructure<T> rint() {
/** {@inheritDoc}
*/
@Override
public FieldDerivativeStructure<T> signum() {
return factory.constant(data[0].signum());
public FieldDerivativeStructure<T> sign() {
return factory.constant(data[0].sign());
}

/**
Expand Down
Expand Up @@ -436,8 +436,8 @@ public FieldGradient<T> rint() {

/** {@inheritDoc} */
@Override
public FieldGradient<T> signum() {
return newInstance(FastMath.signum(value));
public FieldGradient<T> sign() {
return newInstance(FastMath.sign(value));
}

/**
Expand Down
Expand Up @@ -307,8 +307,8 @@ public FieldUnivariateDerivative1<T> rint() {

/** {@inheritDoc} */
@Override
public FieldUnivariateDerivative1<T> signum() {
return new FieldUnivariateDerivative1<>(FastMath.signum(f0), f0.getField().getZero());
public FieldUnivariateDerivative1<T> sign() {
return new FieldUnivariateDerivative1<>(FastMath.sign(f0), f0.getField().getZero());
}

/**
Expand Down
Expand Up @@ -335,9 +335,9 @@ public FieldUnivariateDerivative2<T> rint() {

/** {@inheritDoc} */
@Override
public FieldUnivariateDerivative2<T> signum() {
public FieldUnivariateDerivative2<T> sign() {
final T zero = f0.getField().getZero();
return new FieldUnivariateDerivative2<>(FastMath.signum(f0), zero, zero);
return new FieldUnivariateDerivative2<>(FastMath.sign(f0), zero, zero);
}

/**
Expand Down
Expand Up @@ -359,7 +359,7 @@ public Gradient rint() {

/** {@inheritDoc} */
@Override
public Gradient signum() {
public Gradient sign() {
return newInstance(FastMath.signum(value));
}

Expand Down
Expand Up @@ -434,7 +434,7 @@ public SparseGradient rint() {

/** {@inheritDoc} */
@Override
public SparseGradient signum() {
public SparseGradient sign() {
return createConstant(FastMath.signum(value));
}

Expand Down
Expand Up @@ -248,7 +248,7 @@ public UnivariateDerivative1 rint() {

/** {@inheritDoc} */
@Override
public UnivariateDerivative1 signum() {
public UnivariateDerivative1 sign() {
return new UnivariateDerivative1(FastMath.signum(f0), 0.0);
}

Expand Down
Expand Up @@ -272,7 +272,7 @@ public UnivariateDerivative2 rint() {

/** {@inheritDoc} */
@Override
public UnivariateDerivative2 signum() {
public UnivariateDerivative2 sign() {
return new UnivariateDerivative2(FastMath.signum(f0), 0.0, 0.0);
}

Expand Down

This file was deleted.

Expand Up @@ -1812,11 +1812,15 @@ public Complex remainder(final Complex a) {
}

/** {@inheritDoc}
* @since 1.7
* @since 2.0
*/
@Override
public Complex signum() {
return createComplex(FastMath.signum(getRealPart()), FastMath.signum(getImaginaryPart()));
public Complex sign() {
if (isNaN() || isZero()) {
return this;
} else {
return this.divide(FastMath.hypot(real, imaginary));
}
}

/** {@inheritDoc}
Expand Down
Expand Up @@ -1923,8 +1923,12 @@ public FieldComplex<T> remainder(final FieldComplex<T> a) {

/** {@inheritDoc} */
@Override
public FieldComplex<T> signum() {
return createComplex(FastMath.signum(getRealPart()), FastMath.signum(getImaginaryPart()));
public FieldComplex<T> sign() {
if (isNaN() || isZero()) {
return this;
} else {
return this.divide(FastMath.hypot(real, imaginary));
}
}

/** {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion hipparchus-core/src/main/java/org/hipparchus/dfp/Dfp.java
Expand Up @@ -2722,7 +2722,7 @@ public Dfp remainder(final double a) {
/** {@inheritDoc}
*/
@Override
public Dfp signum() {
public Dfp sign() {
if (isNaN() || isZero()) {
return this;
} else {
Expand Down

0 comments on commit 2b59ff3

Please sign in to comment.