Subject: Re: Castings...
To: Chris G. Demetriou <cgd@pa.dec.com>
From: Neil A. Carson <neil@causality.com>
List: tech-kern
Date: 10/08/1997 17:44:48
Chris G. Demetriou wrote:
>
> > Situation:
> > 1 Casting a negative floating point number to a unsigned integer
> > also
> > 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???
>
> At least under Digital UNIX, the division/remainder rules appear to
> be:
>
> x = N / M
> y = N % M
>
> constrained by:
>
> x * M + y == N
>
> N / M == -((-N) / M )
> N % M == -((-N) % M )
>
> N / M == -(N / (-M))
> N % M == N % (-M)
>
> In other words:
>
> 443 [dnaunix] tmp % cat bar.c
>
> main(){
> printf("%d\n", 12 / 5);
> printf("%d\n", 12 % 5);
>
> printf("%d\n", - 12 / 5);
> printf("%d\n", - 12 % 5);
>
> printf("%d\n", 12 / - 5);
> printf("%d\n", 12 % - 5); ------------------------------
> |
> printf("%d\n", -12 / - 5); |
> printf("%d\n", -12 % - 5); |
> } |
> 444 [dnaunix] tmp % cc bar.c
> 445 [dnaunix] tmp % ./a.out
> 2
> 2
> -2
> -2
> -2
> 2
> 2
> -2
'BSD retains this functionality for ints, but for quads the one hilited
above different (gives -2). Does this mean that the NetBSD moddi3
function should not return negative numbers?
Neil
--
Neil A. Carson Marketing Director
E-mail: neil@causality.com Causality Limited (London, UK)
Mobile: +44 (0)370 593183 Tel/Fax: +44 (0)181 930 7408
Sent from a 233MHz StrongARM NC! Web: http://www.causality.com.