ReactOS 0.4.15-dev-7654-g6bc40d3
ceil.c
Go to the documentation of this file.
1
2/*******************************************************************************
3MIT License
4-----------
5
6Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this Software and associated documentaon files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25*******************************************************************************/
26
27#include "libm.h"
28#include "libm_util.h"
29
30#include "libm_errno.h"
31#define USE_HANDLE_ERROR
32#include "libm_inlines.h"
33#undef USE_HANDLE_ERROR
34
35// Disable "C4163: not available as intrinsic function" warning that older
36// compilers may issue here.
37#pragma warning(disable:4163)
38#pragma function(ceil)
39
40double FN_PROTOTYPE(ceil)(double x)
41{
42 double r;
43 long long rexp, xneg;
44 unsigned long long ux, ax, ur, mask;
45
46 GET_BITS_DP64(x, ux);
47 ax = ux & (~SIGNBIT_DP64);
48 xneg = (ux != ax);
49
50 if (ax >= 0x4340000000000000)
51 {
52 /* abs(x) is either NaN, infinity, or >= 2^53 */
53 if (ax > 0x7ff0000000000000)
54 /* x is NaN */
55 return _handle_error("ceil", OP_CEIL, ux|0x0008000000000000, _DOMAIN, 0,
56 EDOM, x, 0.0, 1);
57 else
58 return x;
59 }
60 else if (ax < 0x3ff0000000000000) /* abs(x) < 1.0 */
61 {
62 if (ax == 0x0000000000000000)
63 /* x is +zero or -zero; return the same zero */
64 return x;
65 else if (xneg) /* x < 0.0 */
66 {
67 PUT_BITS_DP64(SIGNBIT_DP64, r); /* return -0.0 */
68 return r;
69 }
70 else
71 return 1.0;
72 }
73 else
74 {
75 rexp = ((ux & EXPBITS_DP64) >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64;
76 /* Mask out the bits of r that we don't want */
77 mask = 1;
78 mask = (mask << (EXPSHIFTBITS_DP64 - rexp)) - 1;
79 ur = (ux & ~mask);
80 PUT_BITS_DP64(ur, r);
81 if (xneg || (ur == ux))
82 return r;
83 else
84 /* We threw some bits away and x was positive */
85 return r + 1.0;
86 }
87
88}
double __cdecl _handle_error(char *fname, int opcode, unsigned long long value, int type, int flags, int error, double arg1, double arg2, int nargs)
Handles an error condition.
Definition: _handle_error.c:34
#define EDOM
Definition: errno.h:39
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLint GLuint mask
Definition: glext.h:6028
#define _DOMAIN
Definition: math.h:39
_Check_return_ _CRTIMP double __cdecl ceil(_In_ double x)
#define FN_PROTOTYPE(fname)
Definition: libm.h:29
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define SIGNBIT_DP64
Definition: libm_util.h:44
#define EXPBITS_DP64
Definition: libm_util.h:45
#define EXPBIAS_DP64
Definition: libm_util.h:55
#define PUT_BITS_DP64(ux, x)
Definition: libm_util.h:124
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw ax
Definition: synth_sse3d.h:180