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

Message-ID: <3EA5477F.2020901@cyberoptics.com>
Date: Tue, 22 Apr 2003 08:45:35 -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>
In-Reply-To: <fA9pa.20115$1s1.299825@newsfeeds.bigpond.com>
Lines: 39
NNTP-Posting-Host: 65.214.98.62
X-Trace: 1051019114 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

Ben Peddell wrote:

> From your crash, it looks like the divide was being called something 
> like:
> result = div(-3,-3); 

Those args shouldn't even cause it to bomb.  I think I had some problem 
with -fomit-frame-pointer, but I'm still investigating.

> And the results:
>
> Linux div(40,-3) = -13, 1
> Asm   div(40,-3) = -13, 1
> C     div(40,-3) = -13, 1
> DJGPP div(40,-3) = -13, -1 

According to C99:

   6.5.5  Multiplicative operators

   [#6] When integers are divided, the result of the / operator
   is  the  algebraic  quotient  with   any   fractional   part
   discarded.78)   If  the  quotient  a/b is representable, the
   expression (a/b)*b + a%b shall equal a.

...so the 2.03 DJGPP div() is incorrect, since (-13)*(-3) + (-1) != 40.  
I knew this when I submitted 00314, but the log for 00314 claims that 
the bug was fixed in 2000.

> I think you can see the odd one out.
>
> By the way, the libc reference in DJGPP says that the DJGPP result is 
> correct.

OK, so we have a bug in the docs as well.

-Eric Rudd
rudd AT cyberoptics DOT com

- Raw text -


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