Date: Tue, 22 Apr 2003 08:55:21 -0500 From: Eric Rudd Subject: Re: Bug 00314 -- div() still broken In-reply-to: Cc: djgpp-workers AT delorie DOT com Message-id: <3EA549C9.4070307@cyberoptics.com> Organization: CyberOptics MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit X-Accept-Language: en,pdf User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.3) Gecko/20030312 Newsgroups: comp.os.msdos.djgpp References: Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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 > >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 > >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