What is fmodl in C?

Overview

The fmodl() function in C performs the division operation of two input arguments. In mathematical notation, fmodl() performs the function of xy\frac{x}{y}. The fmodl() function in C is defined in the <math.h> header file.

To use the fmodl() function, you must include the <math.h> library at the beginning of your code as shown below:

#include<math.h>

The fmodl() function is defined as below in the <math.h> header file:

long double fmodl( long double x, long double y );

Parameters

The fmodl() function takes two arguments (xx and yy) of type long double as input.

Return value

The fmodl() function returns the remainder if yy divides xx. The return value is of type long double.

Different values of xx and yy can result in varying results and errors:

  1. If x=0x=0 but yy does not, the return value will be 00.
  2. If xx is \infty and yy is a legitimate number, the return value will be Not a Number (NaN).
  3. If yy is \infty and xx is a legitimate number, the return value will be NaN.
  4. If either xx or yy is NaN, the return value will also be NaN.

Example

Below is an example of how you can use fmodl():

#include<stdio.h>
#include<math.h>
int main() {
printf("4.2/2 = %Lf\n", fmodl(4.2,2));
return 0;
}

Explanation

The fmodl() function has been given the arguments such that x=4.2x=4.2 and y=2y=2. The function divides 4.22\frac{4.2}{2} and returns the result of this division.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved