Summation on HP 42S
|
09-30-2018, 03:03 PM
(This post was last modified: 09-30-2018 08:03 PM by Albert Chan.)
Post: #51
|
|||
|
|||
RE: Summation on HP 42S
(09-29-2018 09:10 PM)ijabbott Wrote: Curiously, replacing `i += i;` with `i <<= 1` in the code ... it just returns the value 31. Perhaps << operator assumed unsigned integer (bits operation) ? To confirm, this unsigned version also work: i += (unsigned) i My head tends to think of C int like the CPU, with two-complement wrapping. Just to be safe, now I add -fwrapv flag to my makefile. BTW, older GCC does not optimize this aggressively ... Using *old* GCC 3.4.2, even with -O3, it return the "expected" 31. Update: above bug, failing with newer GCC, is often called time bomb. https://www.cs.utah.edu/~regehr/papers/overflow12.pdf |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 10 Guest(s)