446,234 Members | 1,872 Online Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

# fmod?

 P: n/a Hi! I'm reading a C book, and it says that fmod() returns the remainder of the exact division of it's arguments. Well, in a exact division, the remainder shall always be 0 (zero), so this don't make any logic (I guess). Anyway, foward in the chapter it says that fmod returns the remainder of the integer division of it's arguments. I checked KnR 2nd ed. and the man page, and still can't figure out wich one is correct. Nov 14 '05 #1
6 Replies

 P: n/a stau writes: I'm reading a C book, and it says that fmod() returns the remainder of the exact division of it's arguments. Well, in a exact division, the remainder shall always be 0 (zero), so this don't make any logic (I guess). Anyway, foward in the chapter it says that fmod returns the remainder of the integer division of it's arguments. I checked KnR 2nd ed. and the man page, and still can't figure out wich one is correct. I would go with this. Scan down to fmod. http://www.acm.uiuc.edu/webmonkeys/b.../2.7.html#fmod I found that on google groups with . There are more hits if you don't like this one. I consider Plauger to be definitive in this area. I don't like your book. It is kind of nasty to represent 0 in floating point. AFAIK it is done by definition, rather than an actual result of computation. Nov 14 '05 #2

 P: n/a On Sun, 28 Dec 2003 04:26:25 +0000, stau wrote in comp.lang.c: Hi! I'm reading a C book, and it says that fmod() returns the remainder of the exact division of it's arguments. Well, in a exact division, the remainder shall always be 0 (zero), so this don't make any logic (I guess). Anyway, foward in the chapter it says that fmod returns the remainder of the integer division of it's arguments. I checked KnR 2nd ed. and the man page, and still can't figure out wich one is correct. Here is how the C standard defines it: ======== 7.12.10.1 The fmod functions Synopsis 1 #include double fmod(double x, double y); 2 The fmod functions compute the floating-point remainder of x/y. Returns 3 The fmod functions return the value x - ny, for some integer n such that, if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y. If y is zero, whether a domain error occurs or the fmod functions return zero is implementation defined. ======== No use is made of the word "exact". -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq Nov 14 '05 #3

 P: n/a stau wrote: Hi! I'm reading a C book, and it says that fmod() returns the remainder of the exact division of it's arguments. Well, in a exact division, the remainder shall always be 0 (zero), so this don't make any logic (I guess). Anyway, foward in the chapter it says that fmod returns the remainder of the integer division of it's arguments. I checked KnR 2nd ed. and the man page, and still can't figure out wich one is correct. I don't know what you mean by "exact division." In modular division, if the divisor is a factor of the dividend the result will be zero, i.e. no remainder. The library function fmod() returns the remainder after division with floating point numbers (fractional numbers). It returns type double and its arguments must be doubles. Remember to #include . If you want the remainder after division with integers use the % operator. Its operands must be ints. Nov 14 '05 #4

 P: n/a On Sun, 28 Dec 2003 18:15:43 +0000, John Smith wrote: Sorry, by exact division I meant real division (real arithmetic). That expression is used in my native language. Thanks. Nov 14 '05 #5

 P: n/a In article stau writes: Sorry, by exact division I meant real division (real arithmetic). That expression is used in my native language. And it indeed is (but not necessarily). I think when your book indeed states that fmod performs an exact division it is wrong. What it does do is calculate an exact *integral* quotient and then it returns the associated remainder. -- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131 home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/ Nov 14 '05 #6

 P: n/a On Tue, 30 Dec 2003 00:40:18 +0000, Dik T. Winter wrote: In article stau writes:[SNIP] And it indeed is (but not necessarily). I think when your book indeed states that fmod performs an exact division it is wrong. What it does do is calculate an exact *integral* quotient and then it returns the associated remainder. Yes, I reallized that. The book gives a wild pointer when he states that the fmod function returns the remainder of a real division. Nov 14 '05 #7

### This discussion thread is closed

Replies have been disabled for this discussion. 