Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.

Also, you appear to be using Python 2, the results are different with any modern version of Python.



And here are the two differences I think your expression is hitting on:

    Expression: 750/300
    Python 2.7: 2
    Python 3.9: 2.5
    C: 2.000000
    SQLite: 2
    Node: 2.5
    Java: 2
    Go: 2

    Expression: -123%10
    Python 2.7: 7
    Python 3.9: 7
    C: -3.000000
    SQLite: -3
    Node: -3
    Java: -3
    Go: -3
There might be more. Though, there's a ton of needless obfuscation in your expression.


Certainly not floating point results in C for either of those.

All literals shown (750, 300, -123 and 10) are of type 'int', so the results would be, too.


Yep, I coerced the result to floating point in my harness.

If anyone cares to look: https://pastebin.com/7tLrs28V

I'm probably done, it's a mildly interesting side quest, but really, this is just reinforcing that different languages do things differently.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: