delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/04/22/08:31:38

From: Andrew Cottrell <andnews AT ihug DOT com DOT oz DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bug 00314 -- div() still broken
Date: Tue, 22 Apr 2003 22:17:21 +1000
Organization: ECLiPSE
Lines: 63
Message-ID: <dsbaavskl0dei9epnr9t4qnu2nn16d96sj@4ax.com>
References: <3e9c6920$0$21928$afc38c87@> <fA9pa.20115$1s1 DOT 299825 AT newsfeeds DOT bigpond DOT com>
NNTP-Posting-Host: p137-tnt8.syd.ihug.com.au
Mime-Version: 1.0
X-Trace: lust.ihug.co.nz 1051013846 6705 203.173.147.137 (22 Apr 2003 12:17:26 GMT)
X-Complaints-To: abuse AT ihug DOT co DOT nz
NNTP-Posting-Date: Tue, 22 Apr 2003 12:17:26 +0000 (UTC)
X-Newsreader: Forte Agent 1.92/32.572
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

>Eric Rudd wrote:
>> On 2000-01-18, I submitted bug report 00314, which concerns incorrect 
>> behavior of the div() and ldiv() functions.  The DJGPP bug-tracking 
>> system reports this bug as being fixed, but the latest source appears to 
>> be still unchanged from before, and moreover a call to div() in the 
>> libc.a dated 2001-12-24 from gcc 3.2.2-compiled code now bombs:
The 2.03 looks like it uses the div.c and ldiv.c revision 1.1 . The
fix went into rev 1.2 of the files and are only in the 2.04 WIP CVS
LIBC.

If you want to try out the 2.04 WIP test release goto the following
page and have a read:-
http://clio.rice.edu/djgpp/win2k/main.htm

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;
}

The 204 LIBC ldiv.c is:-

/* 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;
}


Andrew

- Raw text -


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