Calculates the remainder of x/y
as a double precision
value.
Include
<math.h>
Prototype
long double fmodl(long double x, long double y);
Arguments
x
y
Return Value
Returns the remainder of x
divided by y
.
Remarks
If y
= 0, a domain error occurs. If y
is
non-zero, the result will have the same sign as x
and the magnitude of
the result will be less than the magnitude of y
.
Example
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
long double x,y,z;
errno = 0;
x = 7.0;
y = 3.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
errno = 0;
x = 7.0;
y = 7.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
errno = 0;
x = -5.0;
y = 3.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
errno = 0;
x = 5.0;
y = -3.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
errno = 0;
x = -5.0;
y = -5.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
errno = 0;
x = 7.0;
y = 0.0;
z = fmodl(x, y);
if (errno)
perror("Error");
printf("For fmodl(%Lf, %Lf) the remainder is %Lf\n", x, y, z);
}
Example Output
For fmod(7.000000, 3.000000) the remainder is 1.000000
For fmod(7.000000, 7.000000) the remainder is 0.000000
For fmod(-5.000000, 3.000000) the remainder is -2.000000
For fmod(5.000000, -3.000000) the remainder is 2.000000
For fmod(-5.000000, -5.000000) the remainder is -0.000000
Error: domain error
For fmod(7.000000, 0.000000) the remainder is nan