ReactOS 0.4.16-dev-814-g656a5dc
floor.c File Reference
#include <math.h>
#include <limits.h>
Include dependency graph for floor.c:

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES
 

Functions

double __cdecl floor (double x)
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 8 of file floor.c.

Function Documentation

◆ floor()

double __cdecl floor ( double  x)

Definition at line 18 of file floor.c.

19{
20 /* Load the value as uint64 */
21 unsigned long long u64 = *(unsigned long long*)&x;
22
23 /* Check for NAN */
24 if ((u64 & ~(1ULL << 63)) > 0x7FF0000000000000ull)
25 {
26 /* Set error bit */
27 u64 |= 0x0008000000000000ull;
28 return *(double*)&u64;
29 }
30
31 /* Check if x is positive */
32 if ((u64 & (1ULL << 63)) == 0)
33 {
34 /* Check if it fits into an int64 */
35 if (x < (double)_I64_MAX)
36 {
37 /* Just cast to int64, which will truncate towards 0,
38 which is what we want here.*/
39 return (double)(long long)x;
40 }
41 else
42 {
43 /* The exponent is larger than the fraction bits.
44 This means the number is already an integer. */
45 return x;
46 }
47 }
48 else
49 {
50 /* Check if it fits into an int64 */
51 if (x > (double)_I64_MIN)
52 {
53 /* Check if it is -0 */
54 if (x == -0.)
55 {
56 return -0.;
57 }
58
59 /* Cast to int64 to truncate towards 0. If this matches the
60 input, return it as is, otherwise subtract 1 */
61 double y = (double)(long long)x;
62 return (x == y) ? y : y - 1;
63 }
64 else
65 {
66 /* The exponent is larger than the fraction bits.
67 This means the number is already an integer. */
68 return x;
69 }
70 }
71}
ULONG64 u64
Definition: btrfs.h:15
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define _I64_MAX
Definition: limits.h:62
#define _I64_MIN
Definition: limits.h:61
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:89
#define long
Definition: qsort.c:33