ReactOS 0.4.15-dev-7924-g5949c20
modff.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
30float modff(float x, float *iptr)
31{
32 /* modff splits the argument x into integer and fraction parts,
33 each with the same sign as x. */
34
35 unsigned int ux, mask;
36 int xexp;
37
38 GET_BITS_SP32(x, ux);
39 xexp = ((ux & (~SIGNBIT_SP32)) >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
40
41 if (xexp < 0)
42 {
43 /* abs(x) < 1.0. Set iptr to zero with the sign of x
44 and return x. */
45 PUT_BITS_SP32(ux & SIGNBIT_SP32, *iptr);
46 return x;
47 }
48 else if (xexp < EXPSHIFTBITS_SP32)
49 {
50 /* x lies between 1.0 and 2**(24) */
51 /* Mask out the bits of x that we don't want */
52 mask = (1 << (EXPSHIFTBITS_SP32 - xexp)) - 1;
53 PUT_BITS_SP32(ux & ~mask, *iptr);
54 return x - *iptr;
55 }
56 else if ((ux & (~SIGNBIT_SP32)) > 0x7f800000)
57 {
58 /* x is NaN */
59 *iptr = x;
60 return x + x; /* Raise invalid if it is a signalling NaN */
61 }
62 else
63 {
64 /* x is infinity or large. Set iptr to x and return zero
65 with the sign of x. */
66 *iptr = x;
68 return x;
69 }
70}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLint GLuint mask
Definition: glext.h:6028
float modff(float x, float *iptr)
Definition: modff.c:30
#define GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#define SIGNBIT_SP32
Definition: libm_util.h:68
#define EXPBIAS_SP32
Definition: libm_util.h:79
#define PUT_BITS_SP32(ux, x)
Definition: libm_util.h:111
#define EXPSHIFTBITS_SP32
Definition: libm_util.h:80