Skip to content

Commit

Permalink
Canoniclal rounding fix for % operator #268
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszgromada committed Jul 23, 2022
1 parent b1ff898 commit 14ab8f5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.cs 5.0.6 2022-05-30
* @(#)Expression.cs 5.0.7 2022-07-23
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace org.mariuszgromada.math.mxparser {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.0.6
* @version 5.0.7
*
* @see Argument
* @see RecursiveArgument
Expand Down Expand Up @@ -3611,7 +3611,7 @@ private void FACT(int pos) {
*/
private void PERC(int pos) {
double a = getTokenValue(pos - 1);
setToNumber(pos, a * Units.PERC);
setToNumber(pos, MathFunctions.multiply(a, Units.PERC));
tokensList.RemoveAt(pos - 1);
}
/**
Expand Down
16 changes: 15 additions & 1 deletion CURRENT/c-sharp/tests-and-release/4-Unit-Tests/ExpressionTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)ExpressionTest.cs 5.0.6 2022-05-30
* @(#)ExpressionTest.cs 5.0.7 2022-07-23
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -22334,5 +22334,19 @@ public void TestExpr1360() {
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assert.IsTrue(testResult);
}
[TestMethod]
public void TestExpr1361() {
TestCommonTools.testExprSettingsInit();
bool testResult = false;
String expStr = "0.035%";
TestCommonTools.consolePrintTestExprStart(1361, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 0.00035;
if (reg == value)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assert.IsTrue(testResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.java 5.0.6 2022-05-30
* @(#)Expression.java 5.0.7 2022-07-23
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -236,7 +236,7 @@
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.0.6
* @version 5.0.7
*
* @see Argument
* @see RecursiveArgument
Expand Down Expand Up @@ -3648,7 +3648,7 @@ private void FACT(int pos) {
*/
private void PERC(int pos) {
double a = getTokenValue(pos-1);
setToNumber(pos, a * Units.PERC);
setToNumber(pos, MathFunctions.multiply(a, Units.PERC));
tokensList.remove(pos-1);
}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)ExpressionTest.java 5.0.6 2022-05-30
* @(#)ExpressionTest.java 5.0.7 2022-07-23
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -204,7 +204,7 @@
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.0.6
* @version 5.0.7
*
*/
public final class ExpressionTest {
Expand Down Expand Up @@ -22313,4 +22313,18 @@ public void testExpr1360() {
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assertions.assertTrue(testResult);
}
@Test
public void testExpr1361() {
TestCommonTools.testExprSettingsInit();
boolean testResult = false;
String expStr = "0.035%";
TestCommonTools.consolePrintTestExprStart(1361, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 0.00035;
if (reg == value)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assertions.assertTrue(testResult);
}
}

0 comments on commit 14ab8f5

Please sign in to comment.