C Programming - Floating Point Issues - Discussion

Discussion Forum : Floating Point Issues - General Questions (Q.No. 10)
10.
Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
rem = (5.5 % 1.3)
rem = modf(5.5, 1.3)
rem = fmod(5.5, 1.3)
Error: we can't divide
Answer: Option
Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.

Example:


#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
  return 0;
}

Output:
fmod of 5.5 by 1.3 is 0.300000

Discussion:
10 comments Page 1 of 1.

A.Srikanth said:   8 years ago
modf() function is used to calculate integer part and fractional part of a double or float value.

fmod() function is used to calculate modulo division for float and double values since % operator doesn't work for float and double values.
(1)

Tushar said:   9 years ago
fmod() is the library function defined in math.h file.

To calculate remainder of floating point numbers.

Syntax : fmod(x,y);

Mousumi said:   10 years ago
What's the use of 'math.h' and why should we use?

Devendra Pandey said:   10 years ago
According to me.

Rem = (x%y) ___is used to calculate remainder of integer numbers, but it is not applicable for float numbers.

So here we use.

Rem = fmod (x, y) ___where 'fmod' comes in 'math.h' library.

So here option (A) is wrong & option (C) is correct.

Gopi said:   1 decade ago
How is it correct may be modf() and fmod()?

Vindhya said:   1 decade ago
Explain fmod and modf with simple example?

Mamta Kumari said:   1 decade ago
Why option [A] is wrong?

Pinku said:   1 decade ago
What is the error in 5.5% 1.3 if fmod is same as modulus operator?

Mahesh said:   1 decade ago
What is the diffrence between modf() and fmod() functions in C?
(1)

Sandy said:   1 decade ago
What is the function for long division?

Post your comments here:

Your comments will be displayed after verification.