PatchworkOS
Loading...
Searching...
No Matches
modf.c
Go to the documentation of this file.
1
#include <math.h>
2
#include <
stdint.h
>
3
4
// https://cppreference.com/w/c/numeric/math/modf.html
5
double
modf
(
double
x
,
double
* iptr)
6
{
7
if
(
x
== 0.0 ||
x
== -0.0)
8
{
9
*iptr =
x
;
10
return
x
;
11
}
12
13
if
(
isinf
(
x
))
14
{
15
*iptr =
x
;
16
return
x
==
INFINITY
? 0.0 : -0.0;
17
}
18
19
if
(
isnan
(
x
))
20
{
21
*iptr =
NAN
;
22
return
NAN
;
23
}
24
25
double
intPart;
26
double
fracPart = 0.0;
27
if
(
x
> 0.0)
28
{
29
intPart =
floor
(
x
);
30
fracPart =
x
- intPart;
31
}
32
else
33
{
34
intPart =
ceil
(
x
);
35
fracPart =
x
- intPart;
36
}
37
*iptr = intPart;
38
return
fracPart;
39
}
ceil
double ceil(double x)
Definition
ceil.c:5
isinf
#define isinf(x)
Definition
math.h:37
isnan
#define isnan(x)
Definition
math.h:39
floor
double floor(double x)
Definition
floor.c:4
NAN
#define NAN
Definition
math.h:20
INFINITY
#define INFINITY
Definition
math.h:19
modf
double modf(double x, double *iptr)
Definition
modf.c:5
x
int64_t x
Definition
main.c:152
stdint.h
src
libstd
user
functions
math
modf.c
Generated by
1.9.8