← Back to context

Comment by umanwizard

6 hours ago

What is the "even/odd theorem" ?

that all integers are either even or odd, and that for an even integer that integer + 1 and - 1 are odd and vice versa for odd numbers. That the negative numbers have an additional digit from the positive numbers ensures that low(integer) and high(integer) have different parity. So when you wrap around with overflow or underflow you continue to transition from an even to odd, or odd to even.

  • If you need wraparound, you should not use signed integers anyway, as that leads to undefined behavior.

    • Presumably since this language isn't C they can define it however they want to, for instance in rust std::i32::MIN.wrapping_sub(1) is a perfectly valid number.

      1 reply →