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
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include "SDL_endian.h"
22 #define huge really_big /* huge is a reserved keyword in VC++ 6.0 */
23 #define int32_t math_int32_t
24 #define u_int32_t math_u_int32_t
25 typedef Sint32 math_int32_t;
26 typedef Uint32 math_u_int32_t;
28 /* The original fdlibm code used statements like:
29 n0 = ((*(int*)&one)>>29)^1; * index of high word *
30 ix0 = *(n0+(int*)&x); * high word of x *
31 ix1 = *((1-n0)+(int*)&x); * low word of x *
32 to dig two 32 bit words out of the 64 bit IEEE floating point
33 value. That is non-ANSI, and, moreover, the gcc instruction
34 scheduler gets it wrong. We instead use the following macros.
35 Unlike the original code, we determine the endianness at compile
36 time, not at run time; I don't see much benefit to selecting
37 endianness at run time. */
39 /* A union which permits us to convert between a double and two 32 bit
43 * Math on arm is special:
44 * For FPA, float words are always big-endian.
45 * For VFP, floats words follow the memory system mode.
48 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) || \
49 (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
59 } ieee_double_shape_type;
71 } ieee_double_shape_type;
75 /* Get two 32 bit ints from a double. */
77 #define EXTRACT_WORDS(ix0,ix1,d) \
79 ieee_double_shape_type ew_u; \
81 (ix0) = ew_u.parts.msw; \
82 (ix1) = ew_u.parts.lsw; \
85 /* Get the more significant 32 bit int from a double. */
87 #define GET_HIGH_WORD(i,d) \
89 ieee_double_shape_type gh_u; \
91 (i) = gh_u.parts.msw; \
94 /* Get the less significant 32 bit int from a double. */
96 #define GET_LOW_WORD(i,d) \
98 ieee_double_shape_type gl_u; \
100 (i) = gl_u.parts.lsw; \
103 /* Set a double from two 32 bit ints. */
105 #define INSERT_WORDS(d,ix0,ix1) \
107 ieee_double_shape_type iw_u; \
108 iw_u.parts.msw = (ix0); \
109 iw_u.parts.lsw = (ix1); \
113 /* Set the more significant 32 bits of a double from an int. */
115 #define SET_HIGH_WORD(d,v) \
117 ieee_double_shape_type sh_u; \
119 sh_u.parts.msw = (v); \
123 /* Set the less significant 32 bits of a double from an int. */
125 #define SET_LOW_WORD(d,v) \
127 ieee_double_shape_type sl_u; \
129 sl_u.parts.lsw = (v); \
133 /* A union which permits us to convert between a float and a 32 bit
140 } ieee_float_shape_type;
142 /* Get a 32 bit int from a float. */
144 #define GET_FLOAT_WORD(i,d) \
146 ieee_float_shape_type gf_u; \
151 /* Set a float from a 32 bit int. */
153 #define SET_FLOAT_WORD(d,i) \
155 ieee_float_shape_type sf_u; \
169 two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
170 two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
171 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
175 #endif /* _MATH_PRIVATE_H_ */