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
5
double
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
}
errno.h
fmod
double fmod(double x, double y)
Definition
fmod.c:5
EDOM
#define EDOM
Math argument out of domain of func.
Definition
errno.h:197
errno
#define errno
Error number variable.
Definition
errno.h:27
isinf
#define isinf(x)
Definition
math.h:37
isnan
#define isnan(x)
Definition
math.h:39
trunc
double trunc(double x)
Definition
trunc.c:3
NAN
#define NAN
Definition
math.h:20
x
int64_t x
Definition
main.c:152
y
int64_t y
Definition
main.c:153
src
libstd
user
functions
math
fmod.c
Generated by
1.9.8