Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is fmodf in C?

Maham Ghazanfar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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;
}
Execution of function

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.

RELATED TAGS

c

CONTRIBUTOR

Maham Ghazanfar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring