Difference in calculations on Samsung Android vs Apple vs Google vs my own

185 Views Asked by At

While scripting a simple calculator in Javascript I came across this issue while checking my output with output from other calculators

500/5*2/50%2

Samsung = 800 Apple = 100 Google Calc = 800 My calculator = 0.08

My calculator above executes from left to right as all operators have same precedence. But which one is actual correct answere?

1

There are 1 best solutions below

0
On

It surprises many non-mathematicians but there is no standards body setting the rules of mathematics. So, there is often no official answer to questions such as this. Chemistry has IUPAC so a similar question in Chemistry might have an official answer. There is no similar body for mathematics.

There are some points that pretty much all serious mathematicians will agree on e.g. $2 + 3 \times 4 = 14$ rather than $20$. Questions on the meaning of $a / b / c$ don't generally even come up since it would be rare to write that.

% as an operator is just a feature of some programming languages and not mathematics in general. In some languages it may have no meaning and, even when it has a meaning, it may vary from language to language. In your case, I suspect that % is being interpreted quite differently in each case. How do you expect it to be interpreted? I cannot guess what you want.

A particular language will have its rules and hence it may be possible to say what is the correct answer for that language. However, even the language's rules may not cover all cases and it might come down to chance behaviour of the compiler or interpreter.