From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15548 invoked by alias); 9 Nov 2005 19:52:43 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 15536 invoked by uid 22791); 9 Nov 2005 19:52:40 -0000 Received: from mailfe08.swip.net (HELO swip.net) (212.247.154.225) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 09 Nov 2005 19:52:40 +0000 X-T2-Posting-ID: 2yF4ydxc0UI9xI7FHZPfog== Received: from 83.72.134.122.ip.tele2adsl.dk ([83.72.134.122] verified) by mailfe08.swip.net (CommuniGate Pro SMTP 5.0.1) with ESMTP id 5278636 for gcc-help@gcc.gnu.org; Wed, 09 Nov 2005 20:52:32 +0100 From: Frans Englich To: gcc-help@gcc.gnu.org Subject: Re: Remainder ( % ) operator and GCC Date: Wed, 09 Nov 2005 19:52:00 -0000 User-Agent: KMail/1.8.50 References: <4371F73D.30201@mbox.vol.cz> <200511091944.49730.frans.englich@telia.com> <2e393d080511091138h6fc12396kc56246b9dea449f6@mail.gmail.com> In-Reply-To: <2e393d080511091138h6fc12396kc56246b9dea449f6@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511092003.28304.frans.englich@telia.com> X-SW-Source: 2005-11/txt/msg00136.txt.bz2 On Wednesday 09 November 2005 19:38, corey taylor wrote: > You could use fmod. But isn't fmod for floating point mod computation? From what I've understood "%" when invoked with integers beforms integer remainder compuation, as opposed to floating point. Cheers, Frans > > corey > > On 11/9/05, Frans Englich wrote: > > On Wednesday 09 November 2005 19:19, Ian Lance Taylor wrote: > > > Ladislav Mecir writes: > > > > Could you give me an advice how to make the following program (and > > > > programs using many times the % operator) run reliably when compiled > > > > by GCC on different operating systems even when the user gives -1 as > > > > the B value? > > > > > > > > #include > > > > int main(int argc, char *argv[]) { > > > > int a = -2147483647; > > > > int b; > > > > printf ("The value of B: "); > > > > scanf ("%i", &b); > > > > printf ("%i %% %i: %i", a, b, (a - 1) % b); > > > > return 0; > > > > } > > > > > > Don't use '%'. It is machine dependent when used with a negative > > > number. > > > > What should one use instead? What is the portable, machine-independent > > alternative? > > > > > > Cheers, > > > > Frans