This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [ping][patch] Fixed-point patch 2/10
Mark Mitchell wrote:
Fu, Chao-Ying wrote:
Ex 2: (A and B are negative. )
A.high = 0xffffffffffffffff and A.low = 0x8000000000000000
B.high = 0xffffffffffffffff and B.low = 0x0000000000000001
=> A > B,
because A.high == B.high and
(unsigned HOST_WIDE_INT) a.low > (unsigned HOST_WIDE_INT) b.low
Yes, I see; two's complement is set up so that after masking the sign
bit, you can do an unsigned compare. Thank you for explaining.
Since double_int is already declared with low unsigned, like this:
typedef struct
{
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT high;
} double_int;
Would it be more obvious to simply remove the casts altogether, e.g.
double_int_scmp (double_int a, double_int b)
{
if (a.high < b.high)
return -1;
if (a.high > b.high)
return 1;
if (a.low < b.low)
return -1;
if (a.low > b.low)
return 1;
return 0;
}
Nigel