How do I detect if a system is fully 2's complement?

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 [2] is flawed. 4. ~1 == -2 Also 2's complement, but leaves out the trap possibility (not tried) 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 it sufficient? 7. [6] && [4] (Not tried) Would this be an improvement? Or is it redundant? -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Daryle Walker <darylew@hotmail.com> writes:
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?
Do you need to know at preprocessing time, compile time, or runtime? -- Dave Abrahams Boost Consulting www.boost-consulting.com

On 11/12/06 12:27 PM, "David Abrahams" <dave@boost-consulting.com> wrote:
Daryle Walker <darylew@hotmail.com> writes:
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?
Do you need to know at preprocessing time, compile time, or runtime?
I need it during preprocessing. Look at test case "patch_1438626_test" in "rational_test.cpp" (in our CVS HEAD). I'm curious about the solution for all three times, though. -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
participants (2)
-
Daryle Walker
-
David Abrahams