← Back to context

Comment by ratmice

5 hours ago

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.

    • Nim (the original one, not Nimony) compiles to C, so making basic types work differently from C would involve major performance costs.

  • Signed overflow being UB (while unsigned is defined to wrap) is a quirk of C and C++ specifically, not some fundamental property of computing.

    • Nim (the original one, not Nimony) compiles to C, so making basic types work differently from C would involve major performance costs.

      2 replies →