delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/04/23/16:24:28.2

Date: Tue, 22 Apr 2003 08:55:21 -0500
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: Bug 00314 -- div() still broken
In-reply-to: <dsbaavskl0dei9epnr9t4qnu2nn16d96sj@4ax.com>
Cc: djgpp-workers AT delorie DOT com
Message-id: <3EA549C9.4070307@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
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: <fA9pa.20115$1s1 DOT 299825 AT newsfeeds DOT bigpond DOT com>
<dsbaavskl0dei9epnr9t4qnu2nn16d96sj AT 4ax DOT com>
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

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019