ReactOS 0.4.15-dev-7918-g2a2556c
ceil.c File Reference
#include <math.h>
#include <limits.h>
Include dependency graph for ceil.c:

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES
 

Functions

double __cdecl ceil (double x)
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 8 of file ceil.c.

Function Documentation

◆ ceil()

double __cdecl ceil ( double  x)

Definition at line 18 of file ceil.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 /* Cast to int64 to truncate towards 0. If this matches the
38 input, return it as is, otherwise add 1 */
39 double y = (double)(long long)x;
40 return (x > y) ? y + 1 : y;
41 }
42 else
43 {
44 /* The exponent is larger than the fraction bits.
45 This means the number is already an integer. */
46 return x;
47 }
48 }
49 else
50 {
51 /* Check if it fits into an int64 */
52 if (x > (double)_I64_MIN)
53 {
54 /* Cast to int64 to truncate towards 0. */
55 x = (double)(long long)x;
56 return (x == 0.) ? -0.0 : x;
57 }
58 else
59 {
60 /* The exponent is larger than the fraction bits.
61 This means the number is already an integer. */
62 return x;
63 }
64 }
65}
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:80