PatchworkOS
Loading...
Searching...
No Matches
floor.c
Go to the documentation of this file.
1#include <math.h>
2#include <stdint.h>
3
4double floor(double x)
5{
6 if (isinf(x) || x == 0.0 || x == -0.0)
7 {
8 return x;
9 }
10
11 if (isnan(x))
12 {
13 return NAN;
14 }
15
16 if (fabs(x) >= INT64_MAX)
17 {
18 return x;
19 }
20
21 int64_t intPart = (int64_t)x;
22 if (x < 0.0 && x != (double)intPart)
23 {
24 intPart--;
25 }
26
27 return (double)intPart;
28}
double floor(double x)
Definition floor.c:4
#define isinf(x)
Definition math.h:37
#define isnan(x)
Definition math.h:39
#define NAN
Definition math.h:20
double fabs(double x)
Definition fabs.c:3
int64_t x
Definition main.c:152
__INT64_TYPE__ int64_t
Definition stdint.h:16
#define INT64_MAX
Definition stdint.h:73