Skip to content

Commit

Permalink
#261 BigDecimal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszgromada committed May 29, 2022
1 parent 853b5d0 commit 461e915
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ public static double power(double a, double b) {
if (Double.IsInfinity(b)) Math.Pow(a, b);
double babs = Math.Abs(b);
double bint = Math.Round(babs);
if ( MathFunctions.abs(babs - bint) <= BinaryRelations.DEFAULT_COMPARISON_EPSILON ) {
if ( MathFunctions.abs(babs - bint) <= BinaryRelations.DEFAULT_COMPARISON_EPSILON && babs < int.MaxValue && -babs > int.MinValue) {
if (b >= 0) return powInt(a, (int)bint);
else return powInt(a, -(int)bint);
} else if (a >= 0)
Expand Down
28 changes: 28 additions & 0 deletions CURRENT/c-sharp/tests-and-release/4-Unit-Tests/ExpressionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22292,6 +22292,34 @@ public void TestExpr1357() {
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assert.IsTrue(testResult);
}
[TestMethod]
public void TestExpr1358() {
TestCommonTools.testExprSettingsInit();
bool testResult = false;
String expStr = "3!<=3^2^9^92^9~&2";
TestCommonTools.consolePrintTestExprStart(1358, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 0;
if (MathFunctions.abs(reg - value) <= 1e-14)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assert.IsTrue(testResult);
}
[TestMethod]
public void TestExpr1359() {
TestCommonTools.testExprSettingsInit();
bool testResult = false;
String expStr = "2^2^^2^2^^2^2^^2222∛2^9^92^92^^0=2^9^92^9^2^2^9^92^92^^0=222^22^^2^9^9<--2^92^^0<2^9^92^9^2^2^9^92^92^^0=2^9^92^92";
TestCommonTools.consolePrintTestExprStart(1359, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 1;
if (MathFunctions.abs(reg - value) <= 1e-14)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assert.IsTrue(testResult);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ public static double power(double a, double b) {
if (Double.isInfinite(b)) Math.pow(a, b);
double babs = Math.abs(b);
double bint = Math.round(babs);
if ( MathFunctions.abs(babs - bint) <= BinaryRelations.DEFAULT_COMPARISON_EPSILON ) {
if ( MathFunctions.abs(babs - bint) <= BinaryRelations.DEFAULT_COMPARISON_EPSILON
&& babs < Integer.MAX_VALUE && -babs > Integer.MIN_VALUE) {
if (b >= 0) return powInt(a, (int)bint);
else return powInt(a, -(int)bint);
} else if (a >= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22271,4 +22271,32 @@ public void testExpr1357() {
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assertions.assertTrue(testResult);
}
@Test
public void testExpr1358() {
TestCommonTools.testExprSettingsInit();
boolean testResult = false;
String expStr = "3!<=3^2^9^92^9~&2";
TestCommonTools.consolePrintTestExprStart(1358, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 0;
if (MathFunctions.abs(reg - value) <= 1e-14)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assertions.assertTrue(testResult);
}
@Test
public void testExpr1359() {
TestCommonTools.testExprSettingsInit();
boolean testResult = false;
String expStr = "2^2^^2^2^^2^2^^2222∛2^9^92^92^^0=2^9^92^9^2^2^9^92^92^^0=222^22^^2^9^9<--2^92^^0<2^9^92^9^2^2^9^92^92^^0=2^9^92^92";
TestCommonTools.consolePrintTestExprStart(1359, expStr);
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 1;
if (MathFunctions.abs(reg - value) <= 1e-14)
testResult = true;
TestCommonTools.consolePrintTestExprEnd(value, reg, testResult, testExp);
Assertions.assertTrue(testResult);
}
}

0 comments on commit 461e915

Please sign in to comment.