fmod?

S

stau

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.
 
J

Jack Klein

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 <math.h>

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
 
O

osmium

stau said:
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/book/c_guide/2.7.html#fmod

I found that on google groups with <fmod plauger>. 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.
 
J

John Smith

stau said:
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 <math.h>. If you want the
remainder after division with integers use the % operator. Its
operands must be ints.
 
S

stau

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.
 
D

Dik T. Winter

> 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.
 
S

stau

[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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top