cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cmath (math.h) : fmod
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cmath (math.h)
functions:
· acos
· asin
· atan
· atan2
· ceil
· cos
· cosh
· exp
· fabs
· floor
· fmod
· frexp
· ldexp
· log
· log10
· modf
· pow
· sin
· sinh
· sqrt
· tan
· tanh
macro constants:
· HUGE_VAL

-

fmod function
     double fmod (      double numerator,      double denominator );
      float fmod (       float numerator,       float denominator );
long double fmod ( long double numerator, long double denominator );
<cmath>

Compute remainder of division

Returns the floating-point remainder of numerator/denominator.

The remainder of a division operation is the result of subtracting the integral quotient multiplied per the denominator from the numerator:

remainder = numerator - quotient * denominator

Parameters

x
Floating point value.

Return Value

The remainder of dividing the arguments.

Portability

In C, only the double version of this function exists with this name.

Example

/* fmod example */
#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 5.3 / 2 is %lf\n", fmod (5.3,2) );
  printf ("fmod of 18.5 / 4.2 is %lf\n", fmod (18.5,4.2) );
  return 0;
}

Output:


fmod of 5.3 / 2 is 1.300000
fmod of 18.5 / 4.2 is 1.700000

See also

fabs Compute absolute value (function)
modf Break into fractional and integral parts (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us