1/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
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
8 * is preserved.
9 * ====================================================
10 */
11
12/*
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $Id$
15 */
16
17#ifndef _MATH_PRIVATE_H_
18#define _MATH_PRIVATE_H_
19
20#include "SDL_name.h"
21#include "SDL_endian.h"
22
23#define huge		really_big /* huge is a reserved keyword in VC++ 6.0 */
24#define u_int32_t	uint32_t
25
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.  */
36
37/* A union which permits us to convert between a double and two 32 bit
38   ints.  */
39
40/*
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.
44 */
45
46#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) || \
47    (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
48
49typedef union
50{
51  double value;
52  struct
53  {
54    u_int32_t msw;
55    u_int32_t lsw;
56  } parts;
57} ieee_double_shape_type;
58
59#else
60
61typedef union
62{
63  double value;
64  struct
65  {
66    u_int32_t lsw;
67    u_int32_t msw;
68  } parts;
69} ieee_double_shape_type;
70
71#endif
72
73/* Get two 32 bit ints from a double.  */
74
75#define EXTRACT_WORDS(ix0,ix1,d)				\
76do {								\
77  ieee_double_shape_type ew_u;					\
78  ew_u.value = (d);						\
79  (ix0) = ew_u.parts.msw;					\
80  (ix1) = ew_u.parts.lsw;					\
81} while (0)
82
83/* Get the more significant 32 bit int from a double.  */
84
85#define GET_HIGH_WORD(i,d)					\
86do {								\
87  ieee_double_shape_type gh_u;					\
88  gh_u.value = (d);						\
89  (i) = gh_u.parts.msw;						\
90} while (0)
91
92/* Get the less significant 32 bit int from a double.  */
93
94#define GET_LOW_WORD(i,d)					\
95do {								\
96  ieee_double_shape_type gl_u;					\
97  gl_u.value = (d);						\
98  (i) = gl_u.parts.lsw;						\
99} while (0)
100
101/* Set a double from two 32 bit ints.  */
102
103#define INSERT_WORDS(d,ix0,ix1)					\
104do {								\
105  ieee_double_shape_type iw_u;					\
106  iw_u.parts.msw = (ix0);					\
107  iw_u.parts.lsw = (ix1);					\
108  (d) = iw_u.value;						\
109} while (0)
110
111/* Set the more significant 32 bits of a double from an int.  */
112
113#define SET_HIGH_WORD(d,v)					\
114do {								\
115  ieee_double_shape_type sh_u;					\
116  sh_u.value = (d);						\
117  sh_u.parts.msw = (v);						\
118  (d) = sh_u.value;						\
119} while (0)
120
121/* Set the less significant 32 bits of a double from an int.  */
122
123#define SET_LOW_WORD(d,v)					\
124do {								\
125  ieee_double_shape_type sl_u;					\
126  sl_u.value = (d);						\
127  sl_u.parts.lsw = (v);						\
128  (d) = sl_u.value;						\
129} while (0)
130
131/* A union which permits us to convert between a float and a 32 bit
132   int.  */
133
134typedef union
135{
136  float value;
137  u_int32_t word;
138} ieee_float_shape_type;
139
140/* Get a 32 bit int from a float.  */
141
142#define GET_FLOAT_WORD(i,d)					\
143do {								\
144  ieee_float_shape_type gf_u;					\
145  gf_u.value = (d);						\
146  (i) = gf_u.word;						\
147} while (0)
148
149/* Set a float from a 32 bit int.  */
150
151#define SET_FLOAT_WORD(d,i)					\
152do {								\
153  ieee_float_shape_type sf_u;					\
154  sf_u.word = (i);						\
155  (d) = sf_u.value;						\
156} while (0)
157
158
159#ifdef __STDC__
160static const double
161#else
162static double
163#endif
164zero    =  0.0,
165one	=  1.0,
166two	=  2.0,
167two53	=  9007199254740992.0,	/* 0x43400000, 0x00000000 */
168two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
169twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
170huge   = 1.0e+300,
171tiny   = 1.0e-300;
172
173#endif /* _MATH_PRIVATE_H_ */
174