The bug isn't so simple to explain...by (no login)
Firstly, all decimal, hexadecimal and octal numbers as unsigned numbers. Negation (-) is an operator in C++, which when applied turns the result into a signed value.
But that isn't the bug that needed fixing. Look at the following lines of C code:
if (-214748364<0) exit(8);
if (-2147483648<0) exit(8);
if (-21474836480<0) exit(8);
In theory, you'd think all would exit and return 8, right? Wrong! Only the top and bottom lines return 8, the middle one doesn't. Such is the way of C, but not the way of BASIC, so I implemented a workaround. The bug happens because the compiler is looking at the number before it applies the negation operator and if the unsigned value fits in a 4 byte integer it computes the equation using 32-bit processing. Of course, 2147483649 may fit in an unsigned 32-bit integer but as soon as negation is applied and the result suddenly doesn't fit anymore... bad stuff happens.
In conclusion, C is weird.
|Response Title||Author and Date|
|Thanks for the extra info!||rpgfan3233 on Apr 10|