Subject: modulus operator in c
To: None <current-users@NetBSD.ORG>
From: Andrew Brown <>
List: current-users
Date: 01/22/1997 12:30:51
just a simple query, not necessarily related to netbsd although it
might be interesting to find out...

does anyone out there who compiles and runs this program

   #include <stdio.h>
   int main(void)
     int dividend,divisor,quotient,remainder;
     printf("%d %d %d %d\n",dividend,divisor,quotient,remainder);

not get

   -3 -2 1 -1

as output?  any system at all, any os at all...i'm trying to find something
somewhere that does not.  the reason stems from the k&r book's definition
on what the quotient and remainder will be from integer arithmetic.  see
section A7.6, paragraph 4:

    "....  If both operands are non-negative, then the remainder is non-
  negative and smaller than the divisor; if not, it is guaranteed only
  that the absolute value of the remainder is smaller than the absolute
  value of the divisor."

if anyone finds such a machine, please let me know...?

|-----< "CODE WARRIOR" >-----| (TheMan)        * "ah!  i see you have the internet                               that goes *ping*!"      * "information is power -- share the wealth."