What is fmodf in C?

The fmodf function, a variation of the fmod function, calculates the remainder of the division of two numbers. It is available for use in the math.h header file.

fmodf uses arguments of type float.

Visual depiction of the function

Prototype

float fmodf(float x, float y)

Parameter and return value

Parameters

  • x: floating-point numerator in the division (divisor)
  • y : floating-point denominator in the division (dividend)

Return value

  • A float type remainder of x/y is returned. The return value is equivalent to x - n*y, where n is equal to the quotient of x/y.

The return value’s sign is the same as the sign associated with x.

Special cases

fmodf(0, y)

fmodf(x, y)

fmodf(x, ∞)

Return value: 0, if y is nonzero

Return value: NaN, if either y is 0 or x is .

Return value: x, if x is not .

Code

#include <stdio.h>
#include <math.h>
int main() {
float a, b, result;
a = 10.4;
b = 3.5;
result = fmodf(a, b);
printf ("The remainder is: %f", result); // %f is the string formatting placeholder for a floating-point number
return 0;
}

In the code above, two floating-point numbers are passed as arguments to fmodf. The returned floating-point number is stored in the result variable, then it’s displayed.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved