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 <frans.englich@xxxxxxxxx> wrote: > > On Wednesday 09 November 2005 19:19, Ian Lance Taylor wrote: > > > Ladislav Mecir <lmecir@xxxxxxxxxxx> 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 <stdio.h> > > > > 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