Subject: Re: Castings...
To: Neil A. Carson <neil@causality.com>
From: None <mika@cs.caltech.edu>
List: tech-kern
Date: 10/08/1997 17:10:27
"Neil A. Carson" writes:
[...]
> 2 12 % -5 (both long longs)
>
>Initially on the ARM we returned a NaN for the 1, (now zero) and the
>present long long code returns -2 --- surely this should be 2, and a
>remainder always be positive???
>
>Input welcomed.
>
> Cheers,
>
> Neil
>
>
I'm not 100% sure this is what you mean, but Hennessey and Patterson
says that the values of the quotient and remainder should be
unaffected by the sign. Thus
12 / -5 = -2 R -2
since of course always (and this I think supercedes whatever one may
believe about the sign of the remainder):
dividend * quotient + remainder = divisor
On the other hand, the "mathematical" modulus is always positive---thus,
if one is to believe H&P, there is a distinction between "remainder" and
"modulus," C's % being an example of the former.
#define mod(x,b) ( ((x)%(b) + (b))%(b) )
Mika