Pelles C forum

C language => Beginner questions => Topic started by: andre104 on November 27, 2012, 05:27:32 AM

Title: The case of fmod?
Post by: andre104 on November 27, 2012, 05:27:32 AM
I know that in C we can calculate the modulus operation of floating points using fmod.
I'd like to ask what are the cases in which such operation is needed?

What I mean is floating point number is an un-exact representation. Dividing a float with a float yields another float.
So, why we do this?  :-\

Title: Re: The case of fmod?
Post by: akko on November 28, 2012, 12:39:31 PM
This can only be answered within the context of your specific problem domain.

If you need more generic information, try
http://floating-point-gui.de/
and
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Title: Re: The case of fmod?
Post by: CommonTater on November 28, 2012, 04:07:21 PM
I know that in C we can calculate the modulus operation of floating points using fmod.
I'd like to ask what are the cases in which such operation is needed?

What I mean is floating point number is an un-exact representation. Dividing a float with a float yields another float.
So, why we do this?  :-\

I believe it's called "mathematics"....
 
Personally I avoid floating point math whenever possible. *Especially* when you're playing with money.  In Canada we use dollars, which are 100 pennies... so everything is converted to pennies and manipulated with integer math. 
 
There are times to use these "higher functions", and that will depend entirely on what you're doing... Calculating orbital trajectories would be one example.