From: Daryle Walker (darylew_at_[hidden])
Date: 2006-11-04 15:34:20
I'm working on a bug that's only present on machines that use 2's complement
for their built-in integers that use all possible bit combinations (like the
common platforms). How can I detect this?
Stuff I tried (knowing that my system matches):
1. -INT_MIN == INT_MIN
My compiler didn't find it a match for some reason
(Apple's special GCC on Mac OS X 10.4.8)
2. (INT_MIN % 3 != 0) && (INT_MIN % 2 == 0)
This is true, especially since I was doing a GCD(INT_MIN, 6) == 2,
but I don't think it's sufficient.
3. -1 == ~0
This worked. Then I found out that ~0 may trap on some systems
(like 1s' complement). Worse, I found out that INT_MIN could
equal -INT_MAX, leaving out the final power of 2 for trap reasons,
so  is flawed.
4. ~1 == -2
Also 2's complement, but leaves out the trap possibility (not
5. INT_MIN + INT_MAX == -1
This worked. It guarantees the bounds, but not that INT_MIN is
a negative of a power of 2.
6. (INT_MIN + INT_MAX == -1) && ((INT_MIN ^ INT_MAX) == -1)
This is what I currently got. It matches two properties of
2's complement systems that use every bit combination. But is
7.  && 
(Not tried) Would this be an improvement? Or is it redundant?
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk