• Subject: Re: Incorrect expression calculation between programming languages
• From: Oliver Kroth <oliver.kroth@...>
• Date: Fri, 6 Aug 2021 15:49:33 +0200

removing brackets around constants and bracketed terms leaves this expression: (( (   788 * 8.46   )+8342*1.803-1 )*4186.4* 15 )*( (22 % 284/( 7530/( 2 *(    25  -421  )) )*597 % 2663)+7283.8-9.60+167.8644 % 3   )+ 8871

And that reveals that some of the modulo operations are NOT guarded by brackets; i.e. the language's operator preference decides in which order the operands are computed.

E.g. 1 / 2 % 3 may be (1/2) % 3 or 1 / (2%3)
similar multiplication:
1 * 2 % 3 can be (1*2) % 3 or 1 * (2%3)

That could explain some of the differences.

Oliver

Am 06.08.21 um 14:31 schrieb Domingo Alvarez Duarte:
This expression shows that we have several disagreements between programming languages about what is the end result:
=====

EXPR = (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((22%284/((7530/((2)*(((((25))-421))))))*597%2663)+7283.8-9.60+167.8644%((3))))+(8871)

POSTGRESQL = 8291561284461.33301440

SQUILU = 8291561284461.3

JAVA = 8.291561284461331E12

D = 8.29156e+12

SQLITE = 8290383058308.3

PHP = 8035491468054

JAVSCRIPT = 8036090802426.098

MYSQL = 8036090802312.071

PYTHON = 1.1107636287e+13

RUBY = 11107636286950.146

LUA = 11665910614443

=====

And making all operands to modulo operator "%" integer:
=====

EXPR = (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((22%284/((7530/((2)*(((((25))-421))))))*597%2663)+7283.8-9.60+167%((3))))+(8871)

D = 8.29038e+12

JAVA = 8.290383058308305E12

MYSQL = 8034912576159.046

POSTGRESQL = 8290383058308.307200

SQLITE = 8290383058308.3

SQUILU = 8291561284461.3

JAVASCRIPT = 8034912576273.071

PHP = 8035491468054

AMPL = 8.03491e+12

GAMS = 8.03491E+12

PYTHON = 1.11064580608e+13

RUBY = 11106458060797.121

LUA = 11664732388290

====