delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/04/22/10:00:09.1

Message-ID: <3EA549C9.4070307@cyberoptics.com>
Date: Tue, 22 Apr 2003 08:55:21 -0500
From: Eric Rudd <rudd AT cyberoptics DOT com>
Organization: CyberOptics
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.3) Gecko/20030312
X-Accept-Language: en,pdf
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
CC: djgpp-workers AT delorie DOT com
Subject: Re: Bug 00314 -- div() still broken
References: <3e9c6920$0$21928$afc38c87@> <fA9pa.20115$1s1 DOT 299825 AT newsfeeds DOT bigpond DOT com> <dsbaavskl0dei9epnr9t4qnu2nn16d96sj AT 4ax DOT com>
In-Reply-To: <dsbaavskl0dei9epnr9t4qnu2nn16d96sj@4ax.com>
Lines: 66
NNTP-Posting-Host: 65.214.98.62
X-Trace: 1051019700 reader0.ash.ops.us.uu.net 11635 65.214.98.62
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp 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