Mail Archives: djgpp/2003/04/22/10:00:09.1
Andrew Cottrell wrote:
>The 204 LIBC div.c is:-
>
>/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
>/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
>#include <stdlib.h>
>
>div_t
>div(int num, int denom)
>{
> div_t r;
>
> r.rem = num % denom;
> r.quot = num / denom;
>
> return r;
>}
>
OK, this looks correct, and it has a 2000 copyright date. I'm still
puzzled why it didn't get into 2.03.
>The 204 LIBC ldiv.c is:-
>
No, this is lldiv(), not ldiv():
>/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
>/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
>/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
>#include <stdlib.h>
>
>lldiv_t
>lldiv(long long int num, long long int denom)
>{
> lldiv_t r;
>
> if (num > 0 && denom < 0)
> {
> num = -num;
> denom = -denom;
> }
> r.quot = num / denom;
> r.rem = num % denom;
> if (num < 0 && denom > 0)
> {
> if (r.rem > 0)
> {
> r.quot++;
> r.rem -= denom;
> }
> }
> return r;
>}
>
This code has the same problems as the old div() and ldiv(). They
should all look like the simple div() code above, except for trivial
changes to the data types. There should not be any reason to do any
testing of signs.
I'm cc'ing djgpp-workers, though my posting there yesterday hasn't shown
up yet. I'll check the CVS code and follow up on djgpp-workers.
Thanks, guys, for checking this out.
-Eric Rudd
rudd AT cyberoptics DOT com
- Raw text -