MathParser.org-mXparser icon indicating copy to clipboard operation
MathParser.org-mXparser copied to clipboard

Updated to use BigInteger.mod function for integer values, or

Open manuelvcr opened this issue 7 years ago • 2 comments

Updated to use BigInteger.mod function for integer values, or BigDecimal.remainder for decimal values and avoid wrong results when we use the MOD or MODULO function with large numbers.

manuelvcr avatar Mar 23 '18 10:03 manuelvcr

You are using tokenString - this will not work in general case, tokeString are available onlyh at the beginning, modulo function can be called also with parameters that are results of further calculations, i.e.

Expression e = new Expression("mod(2^3+sin(pi), 4*3)");

mariuszgromada avatar Jul 08 '18 17:07 mariuszgromada

Hi, so we can change code to user tokenValue instead of tokenString:

private String getTokenValueAsString (int tokenIndex) {
		return Double.toString(tokensList.get(tokenIndex).tokenValue);
	}

I can check if result of module is same that using my first implementation.

manuelvcr avatar Dec 13 '18 07:12 manuelvcr