-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Simple division Expression returns invalid value #310
Comments
Thanks. Have you been trying switching off smart rounding settings? Below the link tot he section in the tutorial: https://mathparser.org/mxparser-tutorial/smart-rounding-settings/ Best regards |
@mariuszgromada I didn't change any default settings mXparser.checkIfAlmostIntRounding(); // true
mXparser.checkIfUlpRounding(); // false
mXparser.checkIfCanonicalRounding(); // true I encountered this bug when I upgraded from 4.4.2 to 5.2.1. On version 4.4.2 this bug doesn't occur but when I upgraded to 5.2.1 this bug is present. |
I belive there was a bug in 4.4 with default settings. Can you switch off all the roundings? |
@mariuszgromada On both 4.4.2 and 5.2.1 only AlmostIntRounding and CanonicalRounding are enabled by default. Version 4.4.2
mXparser.checkIfAlmostIntRounding(); // true
mXparser.checkIfUlpRounding(); // false
mXparser.checkIfCanonicalRounding(); // true
Version 5.2.1
mXparser.checkIfAlmostIntRounding(); // true
mXparser.checkIfUlpRounding(); // false
mXparser.checkIfCanonicalRounding(); // true Also I can see that this bug is present since version v5.0.7, on v5.0.6 the bug is not present. When I call |
Can you run this code for me?
|
Can you also make a test using more fresh .net framework? |
It returns the following output, clearly disabling CanonicalRounding fixes this issue.
|
Ok, now pls see my result when canonical rounding is enabled
Result
I am using a newer version of .net, I suspect the implementation difference in .net between 4.7.2 (your older version) and others. Can you test this on e.g. .net6 or some other version? |
I am executing the code you sent me in the mXparser source UnitTests projects. I can see that it fails only for .NET Framework and .NET Standard libraries, for .NET Core it works properly. I created another test case for the code you just sent to execute it in the mXparser source UnitTests projects (4-Unit-Tests-Core, 4-Unit-Tests-Net, 4-Unit-Tests-Stand) [TestMethod]
public void testExpr1405()
{
mXparser.disableAlmostIntRounding();
mXparser.enableCanonicalRounding();
mXparser.disableUlpRounding();
String expStr = "0.0000004566969933 / 36370.51937825058";
Expression testExp = new Expression(expStr);
double value = testExp.calculate();
double reg = 0.0000004566969933 / 36370.51937825058;
System.Console.WriteLine("value = " + value);
System.Console.WriteLine("reg = " + reg);
} The code you sent gives the different outputs for .NET Core and .NET Framework/Standard. 4-Unit-Tests-Core
value = 1,2556791E-11
reg = 1,2556790530000044E-11
4-Unit-Tests-Net
value = 1E-11
reg = 1,255679053E-11
4-Unit-Tests-Stand
value = 1E-11
reg = 1,255679053E-11 |
I believe I am facing consequence of this |
I am using to string conversion in canonical rounding. |
That could be the cause, I think we should take a look at commits between v5.0.6 and v5.0.7 because the bug is not present in v5.0.6 and is present in v5.0.7. |
No need. I have fixed the bug in the canonical rounding that was present since 4.4.2. As of now please disable canonical rounding and you are good to go. I will try do identify how to solve the difference between frameworks. Best regards |
Fixed |
MathParser.org-mXparser verssion: v.5.2.1
Framework: .NET Framework 4.7.2
I came into a bug today, please see the following test case that I created to experience the bug:
The bug is that the division returns 1E-11 instead of 1.2556790530000044E-11
Please fix this, I will add a PR for the test case
The text was updated successfully, but these errors were encountered: