PatchworkOS
Loading...
Searching...
No Matches
fmod.c
Go to the documentation of this file.
1#include <errno.h>
2#include <math.h>
3
4// https://en.cppreference.com/w/c/numeric/math/fmod
5double fmod(double x, double y)
6{
7 if ((x == 0.0 || x == -0.0) && (y != 0.0 && y != -0.0))
8 {
9 return x;
10 }
11
12 if (isinf(x) && !isnan(y))
13 {
14 errno = EDOM;
15 return NAN;
16 }
17
18 if ((y == 0.0 || y == -0.0) && !isnan(x))
19 {
20 errno = EDOM;
21 return NAN;
22 }
23
24 if (isinf(y) && !isinf(x))
25 {
26 return x;
27 }
28
29 if (isnan(x) || isnan(y))
30 {
31 return NAN;
32 }
33
34 double quotient = trunc(x / y);
35 double result = x - quotient * y;
36 return result;
37}
double fmod(double x, double y)
Definition fmod.c:5
#define EDOM
Math argument out of domain of func.
Definition errno.h:197
#define errno
Error number variable.
Definition errno.h:27
#define isinf(x)
Definition math.h:37
#define isnan(x)
Definition math.h:39
double trunc(double x)
Definition trunc.c:3
#define NAN
Definition math.h:20
int64_t x
Definition main.c:152
int64_t y
Definition main.c:153