Fixed conversion problems to/from 0 in Decimal Floating Point (Dfp) class.
JIRA: MATH-567 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1099938 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1df5ae529c
commit
ec6dbad43a
|
@ -163,7 +163,7 @@ public class Dfp implements FieldElement<Dfp> {
|
||||||
/** Mantissa. */
|
/** Mantissa. */
|
||||||
protected int[] mant;
|
protected int[] mant;
|
||||||
|
|
||||||
/** Sign bit: & for positive, -1 for negative. */
|
/** Sign bit: 1 for positive, -1 for negative. */
|
||||||
protected byte sign;
|
protected byte sign;
|
||||||
|
|
||||||
/** Exponent. */
|
/** Exponent. */
|
||||||
|
@ -269,6 +269,10 @@ public class Dfp implements FieldElement<Dfp> {
|
||||||
if (exponent == -1023) {
|
if (exponent == -1023) {
|
||||||
// Zero or sub-normal
|
// Zero or sub-normal
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
|
// make sure 0 has the right sign
|
||||||
|
if ((bits & 0x8000000000000000L) != 0) {
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2315,7 +2319,10 @@ public class Dfp implements FieldElement<Dfp> {
|
||||||
|
|
||||||
Dfp y = this;
|
Dfp y = this;
|
||||||
boolean negate = false;
|
boolean negate = false;
|
||||||
if (lessThan(getZero())) {
|
int cmp0 = compare(this, getZero());
|
||||||
|
if (cmp0 == 0) {
|
||||||
|
return sign < 0 ? -0.0 : +0.0;
|
||||||
|
} else if (cmp0 < 0) {
|
||||||
y = negate();
|
y = negate();
|
||||||
negate = true;
|
negate = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
If the output is not quite correct, check for invisible trailing spaces!
|
If the output is not quite correct, check for invisible trailing spaces!
|
||||||
-->
|
-->
|
||||||
<release version="3.0" date="TBD" description="TBD">
|
<release version="3.0" date="TBD" description="TBD">
|
||||||
|
<action dev="luc" type="add" issue="MATH-567" due-to="Michel">
|
||||||
|
Fixed conversion problems to/from 0 in Decimal Floating Point (Dfp) class.
|
||||||
|
</action>
|
||||||
<action dev="luc" type="fix" >
|
<action dev="luc" type="fix" >
|
||||||
Fixed initialization of multistep ODE integrators. Relying on the interpolation model
|
Fixed initialization of multistep ODE integrators. Relying on the interpolation model
|
||||||
of the starter integrator inside only one step was wrong. The model may have a too
|
of the starter integrator inside only one step was wrong. The model may have a too
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.commons.math.dfp;
|
package org.apache.commons.math.dfp;
|
||||||
|
|
||||||
|
import org.apache.commons.math.util.FastMath;
|
||||||
|
import org.apache.commons.math.util.MathUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -1504,4 +1506,13 @@ public class DfpTest {
|
||||||
DfpField.FLAG_INVALID, "Sqrt #9");
|
DfpField.FLAG_INVALID, "Sqrt #9");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIssue567() {
|
||||||
|
DfpField field = new DfpField(100);
|
||||||
|
Assert.assertEquals(0.0, field.getZero().toDouble(), MathUtils.SAFE_MIN);
|
||||||
|
Assert.assertEquals(0.0, field.newDfp(0.0).toDouble(), MathUtils.SAFE_MIN);
|
||||||
|
Assert.assertEquals(-1, FastMath.copySign(1, field.newDfp(-0.0).toDouble()), MathUtils.EPSILON);
|
||||||
|
Assert.assertEquals(+1, FastMath.copySign(1, field.newDfp(+0.0).toDouble()), MathUtils.EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue