Skip to main content
Added a tip thanks to @MartinEnder
Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Arithmetic operator discrepancies

For similar languages or simple polyglots, sometimes it's useful to look for differences in how the languages perform arithmetic. This is because most (non-esoteric) languages have infix arithmetic operators and arithmetic can be a quick and easy way to introduce a difference.

For example:

  • ^ is bitwise XOR in some languages and exponentiation in others
  • / is integer division in some languages and floating point division in others
    • For the integer division languages, -1/2 is -1 in some languages (round down) and 0 in others (round to zero)
  • -1%2 is -1 in some languages and 1 in others
  • --x is a no-op in some languages (double negation) and pre-decrement in others
  • 1/0 gives infinity in some languages and errors out in others
  • 1<<64 gives 0 in some languages (overflow) and 36893488147419103232 in others

Arithmetic operator discrepancies

For similar languages or simple polyglots, sometimes it's useful to look for differences in how the languages perform arithmetic. This is because most (non-esoteric) languages have infix arithmetic operators and arithmetic can be a quick and easy way to introduce a difference.

For example:

  • ^ is bitwise XOR in some languages and exponentiation in others
  • / is integer division in some languages and floating point division in others
  • -1%2 is -1 in some languages and 1 in others
  • --x is a no-op in some languages (double negation) and pre-decrement in others
  • 1/0 gives infinity in some languages and errors out in others
  • 1<<64 gives 0 in some languages (overflow) and 36893488147419103232 in others

Arithmetic operator discrepancies

For similar languages or simple polyglots, sometimes it's useful to look for differences in how the languages perform arithmetic. This is because most (non-esoteric) languages have infix arithmetic operators and arithmetic can be a quick and easy way to introduce a difference.

For example:

  • ^ is bitwise XOR in some languages and exponentiation in others
  • / is integer division in some languages and floating point division in others
    • For the integer division languages, -1/2 is -1 in some languages (round down) and 0 in others (round to zero)
  • -1%2 is -1 in some languages and 1 in others
  • --x is a no-op in some languages (double negation) and pre-decrement in others
  • 1/0 gives infinity in some languages and errors out in others
  • 1<<64 gives 0 in some languages (overflow) and 36893488147419103232 in others
Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Arithmetic operator discrepancies

For similar languages or simple polyglots, sometimes it's useful to look for differences in how the languages perform arithmetic. This is because most (non-esoteric) languages have infix arithmetic operators and arithmetic can be a quick and easy way to introduce a difference.

For example:

  • ^ is bitwise XOR in some languages and exponentiation in others
  • / is integer division in some languages and floating point division in others
  • -1%2 is -1 in some languages and 1 in others
  • --x is a no-op in some languages (double negation) and pre-decrement in others
  • 1/0 gives infinity in some languages and errors out in others
  • 1<<64 gives 0 in some languages (overflow) and 36893488147419103232 in others