delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/05/22/09:37:01

Date: Mon, 22 May 2000 08:36:52 -0500
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: Bug 314
To: djgpp-workers AT delorie DOT com
Message-id: <392937F4.B78491A5@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000518143545 DOT 13603F-100000 AT is>
<39257FA1 DOT 65CAAC89 AT cyberoptics DOT com>
Reply-To: djgpp-workers AT delorie DOT com

Eric Rudd wrote:

> OK, I submitted a "solution" to Bug 314, but I'll see if I can run the diffs
> this weekend and get them uploaded.

Here they are:

*** src/libc/ansi/stdlib/div.old        Sat Dec 10 22:33:46 1994
--- src/libc/ansi/stdlib/div.c  Fri May 19 13:04:36 2000
***************
*** 1,4 ****
! /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>

  div_t
--- 1,4 ----
! /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>

  div_t
***************
*** 6,24 ****
  {
    div_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;
  }
--- 6,13 ----
  {
    div_t r;

    r.rem = num % denom;
!   r.quot = num / denom;
!
    return r;
  }


*** src/libc/ansi/stdlib/div.old        Sat Dec 10 22:33:46 1994
--- src/libc/ansi/stdlib/div.c  Fri May 19 13:04:36 2000
***************
*** 1,4 ****
! /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>

  div_t
--- 1,4 ----
! /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  #include <stdlib.h>

  div_t
***************
*** 6,24 ****
  {
    div_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;
  }
--- 6,13 ----
  {
    div_t r;

    r.rem = num % denom;
!   r.quot = num / denom;
!
    return r;
  }

I have done my own testing, and believe that these modified routines now conform
to the requirements of ANSI, but I would appreciate it if someone else took a
look at the code and verified that the new code is indeed correct.

-Eric Rudd
rudd AT cyberoptics DOT com


- Raw text -


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