2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $Id: math_private.h 1969 2006-02-24 09:57:14Z slouken $
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
21 #include "SDL_endian.h"
23 #define huge really_big /* huge is a reserved keyword in VC++ 6.0 */
24 #define u_int32_t uint32_t
26 /* The original fdlibm code used statements like:
27 n0 = ((*(int*)&one)>>29)^1; * index of high word *
28 ix0 = *(n0+(int*)&x); * high word of x *
29 ix1 = *((1-n0)+(int*)&x); * low word of x *
30 to dig two 32 bit words out of the 64 bit IEEE floating point
31 value. That is non-ANSI, and, moreover, the gcc instruction
32 scheduler gets it wrong. We instead use the following macros.
33 Unlike the original code, we determine the endianness at compile
34 time, not at run time; I don't see much benefit to selecting
35 endianness at run time. */
37 /* A union which permits us to convert between a double and two 32 bit
41 * Math on arm is special:
42 * For FPA, float words are always big-endian.
43 * For VFP, floats words follow the memory system mode.
46 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) || \
47 (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
57 } ieee_double_shape_type;
69 } ieee_double_shape_type;
73 /* Get two 32 bit ints from a double. */
75 #define EXTRACT_WORDS(ix0,ix1,d) \
77 ieee_double_shape_type ew_u; \
79 (ix0) = ew_u.parts.msw; \
80 (ix1) = ew_u.parts.lsw; \
83 /* Get the more significant 32 bit int from a double. */
85 #define GET_HIGH_WORD(i,d) \
87 ieee_double_shape_type gh_u; \
89 (i) = gh_u.parts.msw; \
92 /* Get the less significant 32 bit int from a double. */
94 #define GET_LOW_WORD(i,d) \
96 ieee_double_shape_type gl_u; \
98 (i) = gl_u.parts.lsw; \
101 /* Set a double from two 32 bit ints. */
103 #define INSERT_WORDS(d,ix0,ix1) \
105 ieee_double_shape_type iw_u; \
106 iw_u.parts.msw = (ix0); \
107 iw_u.parts.lsw = (ix1); \
111 /* Set the more significant 32 bits of a double from an int. */
113 #define SET_HIGH_WORD(d,v) \
115 ieee_double_shape_type sh_u; \
117 sh_u.parts.msw = (v); \
121 /* Set the less significant 32 bits of a double from an int. */
123 #define SET_LOW_WORD(d,v) \
125 ieee_double_shape_type sl_u; \
127 sl_u.parts.lsw = (v); \
131 /* A union which permits us to convert between a float and a 32 bit
138 } ieee_float_shape_type;
140 /* Get a 32 bit int from a float. */
142 #define GET_FLOAT_WORD(i,d) \
144 ieee_float_shape_type gf_u; \
149 /* Set a float from a 32 bit int. */
151 #define SET_FLOAT_WORD(d,i) \
153 ieee_float_shape_type sf_u; \
167 two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
168 two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
169 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
173 #endif /* _MATH_PRIVATE_H_ */