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

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3EA54F78.C46438ED@phekda.freeserve.co.uk>
Date: Tue, 22 Apr 2003 15:19:36 +0100
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: andnews AT ihug DOT com DOT oz DOT au
CC: DJGPP newsgroup <djgpp AT delorie DOT com>,
Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
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>

Hello.

Andrew Cottrell wrote:
[snip]
> The 204 LIBC ldiv.c is:-

I think you mean lldiv.c.

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

I'm having trouble understanding why it doesn't just do % and /. Why is there
all this other code?

The bugfix for div, ldiv removed all this other code.

Thanks, bye, Rich =]

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


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