From: dmcnulty@... (Dan McNulty) Date: 2002-03-01T22:12:58+09:00 Subject: Re: Correct use of % (modulus) operator? Ack, quite right. So I haven't actually *used* C for awhile :-) I wonder what operator or function I am recalling that yields a floating point remainder....oh well, its not important anyway. Thanks to all for being gentle. -- Dan Josh Huber wrote in message news:<87elj4g7cd.fsf@paradoxical.net>... > dmcnulty@mindspring.com (Dan McNulty) writes: > > > Coming from a C background, I expected "%" to yield a remainder. > > Coming from a C background, I would have expected you to expect this > result! ;) > > > But the code: > > print "4 mod 2: ", 4.0 % 2.0, "\n" > > print "5 mod 2: ", 5.0 % 2.0, "\n" > > > > gives me: > > 4 mod 2: 0.0 > > 5 mod 2: 1.0 > > > > I was expecting a result of "0.5" for 5 % 2, as 5.0 / 2.0 = 2.5 > > > > This isn't covered very well in the books I have, nor can I find much > > on the 'net. I obviously have missed something rather fundamental. > > 5 % 2 = 1 because 2 goes into 5 twice, with 1 remaining. > > IOW, the % operator is for *integer* remainder only. (just as in C) > > ttyl,