fmod()

Declaration

double fmod(double dX, double dModulus);

Description:

This function returns the modulus of dX with respect to dModulus. This function is similar to the % operator for integers.

Overloads

float fmod(float, float);
double fmod(double, double);
long double fmod(long double, long double);

Related Functions

float fmodf(float, float);
long double fmodl(long double, long double);

* Note: Since C does not allow function overloading, these other versions of this function exist.

Domain

(-∞, ∞) x (0, ∞)

Range

(-∞, ∞)

Periodicity

None

Symmetry

None

Asymptotes

None

 

Example

#include <iostream>
#include <cmath>

int main() {
    using namespace std;

    double dX = 30.1;
    double dModulus = 1.0;
    cout << "x = " << dX <<
        "  Modulus = " << dModulus <<
        "  fmod(x, Modulus) = " << fmod(dX, dModulus) << endl;

    dX = 10.8;
    dModulus = 3.14159;
    cout << "x = " << dX <<
        "  Modulus = " << dModulus <<
        "  fmod(x, Modulus) = " << fmod(dX, dModulus) << endl;

    return 0;
}

Output:

fmod() Output