mXparser code:

Function s = new Function("s(n, x) = if( x >= 1, n, s(n+1, x + rUni(0,1) ) )"); Expression e = new Expression("avg( i, 1, 10000, s(0,0) )", s);

Result:

[mXparser-v.4.1.1] 2.7194

Best regards,

*Mariusz Gromada*

mXparser code:

Function s = new Function("s(n, x) = if( x >= 1, n, s(n+1, x + rUni(0,1) ) )"); Expression e = new Expression("avg( i, 1, 10000, s(0,0) )", s);

Result:

[mXparser-v.4.1.1] 2.7194

Best regards,

*Mariusz Gromada*

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Hi,

I calculate the followig Expression (0.00000000004*0.000000005).calculate() in Java.

The result is Zero. I have tested that the precision of e.calculate is not more than about 1E-14. Is that true or can I have a better precision?What do I wrong? I have another calculator on my phone who calculate up to 1E-60 and more.

Yours

Hi,

Thx for your comment.

This is a result of a change that I implemented some time ago to solve the reported problem with sin(pi/2) equals not exactly 1. Current mXparser behavior is that at the end of expression calculation almost integers are rounded to int. Almost integer is is defined based on the epsilon. This will be changed in the new version, pls see the issue.

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/116

Also - currently mXparser has built-in ulp rounding to solve double precision representation and cases like 0.1+0.1+0.1 <> 0.3. Here you have options that are already available.

mXparser.disableUlpRoundng()

mXparser.enableUlpRoundng()

After new change you will get additionally

mXparser.disableAlmostIntRounding()

mXparser.enableAlmostIntRounding()

Best regards

Hi Mariusz,

Thanks a lot for your fast answer. I read before about the rounding-Problem, but I dont connect it with epsilon. I am writing a little calculator as an android app with your mxparser and it works very well, but I have still many to do. Can you tell me what epsilon is about? 9.99*10-14?

You made a great job in making the mxparser. Many thanks.

Yours

v.4.1.1 at the end of calculate method tuns the following code:

double resultint = Math.round(result);

if ( MathFunctions.abs(result-resultint) <= BinaryRelations.getEpsilon() ) result = resultint; return result; You can change this epsilon by mXparser.setEpsilon(double epsilon) which will execute BinaryRelations.setEpsilon(double epsilon) So, you can use this as a workaround, i.e. setting mXparser.setEpsilon(0) But this will be changed and in v.4.2.0 I will introduce dedicated options. best regards

Thank you very much. This is what I want. Now I can calculate very small numbers.

Youre the best :-))))))

The other option you can use is mXparser.disableUlpRounding()

I tried both , but epsilon setting to 1E-99 or higher is the best way. So I can calculate more than 10 decimal numbers ( i.e. in both factors of a multiplication) and the exponential notation always shows a result.

When I use the disable method than the limit of epsilon (1E-14) persists.

Once more many thanks to you.

best regards

Ok. Thx. This will be changed in v.4.2

But remember to disable ulp rounding and then set the epsilon to very small number. Ulp rounding is a different story than almost int rounding. ULP stands for Unit in the Last Place. I introduced this to fix double behavior and make it more similar to decimal.

If you like the repo pls give it a star on GitHub ðŸ™‚

https://github.com/mariuszgromada/MathParser.org-mXparser

Best regards