News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

The case of fmod?

Started by andre104, November 27, 2012, 05:27:32 AM

Previous topic - Next topic

andre104

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?  :-\


akko

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

CommonTater

#2
Quote from: 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?  :-\

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.