This expression shows that we have several disagreements between programming languages about what is the end result:<p>=====<p>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)<p>POSTGRESQL = 8291561284461.33301440<p>SQUILU = 8291561284461.3<p>JAVA = 8.291561284461331E12<p>D = 8.29156e+12<p>SQLITE = 8290383058308.3<p>PHP = 8035491468054<p>JAVSCRIPT = 8036090802426.098<p>MYSQL = 8036090802312.071<p>PYTHON = 1.1107636287e+13<p>RUBY = 11107636286950.146<p>LUA = 11665910614443<p>=====
So, we have (at least) different evaluation orders, different meanings of the % operator (How are negative numbers handled?), different meanings of the / operator (is 10/3=3 or 3.3333 — notice that Python3 joins the 8.29e+12 fold!). This shows two things: 1) Even though it is syntactically correct in N different languages, it does not necessarily mean the same thing, and 2) floating-point math has many traps. Neither should be news to the HN readership.
Other than nerdsniping, what is the point of this expression?<p>If you wanted to show how different languages treat modulo, type conversions, division, etc., you could just show individual examples. That would be significantly clearer.<p>Was there some practical reason behind creating this expression, or is it just obfuscation?
Fairly early on in my career I was on a team writing a GUI programming environment (think old school flow charts) that generated ASP (classic) or Java backends. We allowed simple expressions in assignments with the basic arithmetic operators and functions. We parsed them into a tiny AST and output Java or ASP code for them with lots of explicit parens and casts. After fiddling with minor differences in precedence, associativity and implicit casts we still had some cases that did not match. Pairing with a more senior dev we wrote a C program to generate and compare a large number (tens of millions) of random expressions trying to explore the important variables (small and large floats. Floats that cause funny rounding. Long sequences of almost the same precedence etc).<p>We got all three languages to agree to full precision for almost every case but in each run there were stubbornly alway a few dozen we couldn’t get to match for non obvious and seeming random reasons.<p>This was a prototype that never saw real production use and we spent a couple of weeks on it… it always bothered me that we never understood that last 0.00001%
Different languages have different rules around some math operators, notably around order of operations and how % and / handle floating point values. There are much simpler expressions that will yield differences.<p>Also, you appear to be using Python 2, the results are different with any modern version of Python.
It's hardly incorrect that different languages have different semantics, especially considering the mix of types and use of % in that expression. You could just as well complain that they don't all print floating point numbers in the exact same way.
A big part of the oft-overlooked notion of Information Architecture are the twin concepts of Source of Truth and System of Record. Many systems mix or conflate the two or don't consider them at all, other than subconsciously when wrestling with issues of code duplication (split SoT).<p>If the result of a calculation is that important to the functioning of your code, then having three implementations in multiple languages is just madness. You need to pick one to believe, or constantly deal with random catastrophes. Personally I enjoy very much not being woken up at 7 am EST to solve production issues. Almost as much as I hate other people getting kudos for problems that we should have not signed up for in the first place. Arsonist-firefighters exist in every dark corner of the programming world, and in much greater numbers than actual arsonist-firefighters.<p>From a technology selection standpoint, all of this info is extremely important, because it will inform both my choice of tools and my immediate task list to deal with any answers I don't like. But if you're wrestling with this every day, you've already fucked up.
This kind of thing can bite you even when operating purely on integers. E.g., for a long time (it's been fixed for over a dozen years by now though), Python implemented x%n with an intermediate cast to float, with predictably bad results on inputs larger than typical test cases. I had the damnedest time tracking down the culprit since I assumed it had to be serialization, hashing, or one of the standard culprits --- not that integer math was broken.
Try to edit your post and add a \ before each * so it is not interpreted as italics here.<p>Have you tried to simplify it? My guess is that the problem is not in the last "+(8871)".
You couldnt come up with a simpler example? Youve got at least 12 operations there. Pretty much a single division operation wouldve worked about the same