Path: utzoo!attcan!uunet!husc6!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: /, >>, %, and other ugliness... Message-ID: <1351@mcgill-vision.UUCP> Date: 15 Nov 88 09:21:27 GMT References: <3105@hubcap.UUCP> <34112@XAIT.XEROX.COM> <1700@dataio.Data-IO.COM> <1081@dukeac.UUCP> Organization: McGill University, Montreal Lines: 40 In article <1081@dukeac.UUCP>, sbigham@dukeac.UUCP (Scott Bigham) writes: > In article <11529@bellcore.bellcore.com> sjs@ctt.bellcore.com (Stan Switzer) writes: >> Which is to say that you want the MODULUS operation rather than the >> REMAINDER operation. > Errr... The modulus operation IS the remainder operation. The range of i MOD n is [0,n); the range of i REM n depends on the division operation in use, since REM is the operation such that (i REM n) + n * (i DIV n) == i This usually means the range of i REM n is (-n,n), not [0,n), since DIV usually truncates towards zero rather than either infinity. C defines / and % (for integer operands) to be DIV and REM in my terminology above. Having all three flavors of DIV/REM behavior available would be nice, though it could rapidly get confusing. > Consider: > double r; > int i=5; > ... > r=i/4; > What I want is what i/4 -should- do; ie. return r=1.25. Yes, I know > I can say r=(double)(i/4). And get 1.0, same as for r=i/4. Perhaps you meant r=i/4.0 or r=(double)i/4 instead? In what sense "should" i/4 produce 1.25 instead of 1? It may be what *you* want, but it isn't C. > The irony here is that C can't make this simple conversion, Sure it can. All you have to do is ask it to. You seem to expect it to read your mind and somehow realize that you want it to, without your having to tell it so. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu