lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello Oliver !

Thanks for reply !

One of my objectives is to make awareness of this possible problems between different programming languages and provide test cases to help identify the problems and hopefully have a consensus between then to allow code reuse with fewer/no traps.

Cheers !

On 6/8/21 15:49, Oliver Kroth wrote:
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

====


See also posted here https://news.ycombinator.com/item?id=28085642 and https://sqlite.org/forum/forumpost/6885cf9e21