Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/libm/math_private.h
9903 views
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: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
15
*/
16
17
#ifndef _MATH_PRIVATE_H_
18
#define _MATH_PRIVATE_H_
19
20
/* #include <endian.h> */
21
/* #include <sys/types.h> */
22
23
#define _IEEE_LIBM
24
#define attribute_hidden
25
#define libm_hidden_proto(x)
26
#define libm_hidden_def(x)
27
#define strong_alias(x, y)
28
#define weak_alias(x, y)
29
30
#if !defined(SDL_PLATFORM_HAIKU) && !defined(SDL_PLATFORM_PSP) && !defined(SDL_PLATFORM_3DS) && !defined(SDL_PLATFORM_PS2) /* already defined in a system header. */
31
typedef unsigned int u_int32_t;
32
#endif
33
34
#define atan SDL_uclibc_atan
35
#define __ieee754_atan2 SDL_uclibc_atan2
36
#define copysign SDL_uclibc_copysign
37
#define cos SDL_uclibc_cos
38
#define __ieee754_exp SDL_uclibc_exp
39
#define fabs SDL_uclibc_fabs
40
#define floor SDL_uclibc_floor
41
#define __ieee754_fmod SDL_uclibc_fmod
42
#undef __isinf
43
#define __isinf SDL_uclibc_isinf
44
#undef __isinff
45
#define __isinff SDL_uclibc_isinff
46
#undef __isnan
47
#define __isnan SDL_uclibc_isnan
48
#undef __isnanf
49
#define __isnanf SDL_uclibc_isnanf
50
#define __ieee754_log SDL_uclibc_log
51
#define __ieee754_log10 SDL_uclibc_log10
52
#define modf SDL_uclibc_modf
53
#define __ieee754_pow SDL_uclibc_pow
54
#define scalbln SDL_uclibc_scalbln
55
#define scalbn SDL_uclibc_scalbn
56
#define sin SDL_uclibc_sin
57
#define __ieee754_sqrt SDL_uclibc_sqrt
58
#define tan SDL_uclibc_tan
59
60
/* The original fdlibm code used statements like:
61
n0 = ((*(int*)&one)>>29)^1; * index of high word *
62
ix0 = *(n0+(int*)&x); * high word of x *
63
ix1 = *((1-n0)+(int*)&x); * low word of x *
64
to dig two 32 bit words out of the 64 bit IEEE floating point
65
value. That is non-ANSI, and, moreover, the gcc instruction
66
scheduler gets it wrong. We instead use the following macros.
67
Unlike the original code, we determine the endianness at compile
68
time, not at run time; I don't see much benefit to selecting
69
endianness at run time. */
70
71
/* A union which permits us to convert between a double and two 32 bit
72
ints. */
73
74
/*
75
* Math on arm is special:
76
* For FPA, float words are always big-endian.
77
* For VFP, floats words follow the memory system mode.
78
* For Maverick, float words are always little-endian.
79
*/
80
81
#if (SDL_FLOATWORDORDER == SDL_BIG_ENDIAN)
82
83
typedef union
84
{
85
double value;
86
struct
87
{
88
u_int32_t msw;
89
u_int32_t lsw;
90
} parts;
91
} ieee_double_shape_type;
92
93
#else
94
95
typedef union
96
{
97
double value;
98
struct
99
{
100
u_int32_t lsw;
101
u_int32_t msw;
102
} parts;
103
} ieee_double_shape_type;
104
105
#endif
106
107
/* Get two 32 bit ints from a double. */
108
109
#define EXTRACT_WORDS(ix0,ix1,d) \
110
do { \
111
ieee_double_shape_type ew_u; \
112
ew_u.value = (d); \
113
(ix0) = ew_u.parts.msw; \
114
(ix1) = ew_u.parts.lsw; \
115
} while (0)
116
117
/* Get the more significant 32 bit int from a double. */
118
119
#define GET_HIGH_WORD(i,d) \
120
do { \
121
ieee_double_shape_type gh_u; \
122
gh_u.value = (d); \
123
(i) = gh_u.parts.msw; \
124
} while (0)
125
126
/* Get the less significant 32 bit int from a double. */
127
128
#define GET_LOW_WORD(i,d) \
129
do { \
130
ieee_double_shape_type gl_u; \
131
gl_u.value = (d); \
132
(i) = gl_u.parts.lsw; \
133
} while (0)
134
135
/* Set a double from two 32 bit ints. */
136
137
#define INSERT_WORDS(d,ix0,ix1) \
138
do { \
139
ieee_double_shape_type iw_u; \
140
iw_u.parts.msw = (ix0); \
141
iw_u.parts.lsw = (ix1); \
142
(d) = iw_u.value; \
143
} while (0)
144
145
/* Set the more significant 32 bits of a double from an int. */
146
147
#define SET_HIGH_WORD(d,v) \
148
do { \
149
ieee_double_shape_type sh_u; \
150
sh_u.value = (d); \
151
sh_u.parts.msw = (v); \
152
(d) = sh_u.value; \
153
} while (0)
154
155
/* Set the less significant 32 bits of a double from an int. */
156
157
#define SET_LOW_WORD(d,v) \
158
do { \
159
ieee_double_shape_type sl_u; \
160
sl_u.value = (d); \
161
sl_u.parts.lsw = (v); \
162
(d) = sl_u.value; \
163
} while (0)
164
165
/* A union which permits us to convert between a float and a 32 bit
166
int. */
167
168
typedef union
169
{
170
float value;
171
u_int32_t word;
172
} ieee_float_shape_type;
173
174
/* Get a 32 bit int from a float. */
175
176
#define GET_FLOAT_WORD(i,d) \
177
do { \
178
ieee_float_shape_type gf_u; \
179
gf_u.value = (d); \
180
(i) = gf_u.word; \
181
} while (0)
182
183
/* Set a float from a 32 bit int. */
184
185
#define SET_FLOAT_WORD(d,i) \
186
do { \
187
ieee_float_shape_type sf_u; \
188
sf_u.word = (i); \
189
(d) = sf_u.value; \
190
} while (0)
191
192
/* ieee style elementary functions */
193
extern double __ieee754_sqrt(double) attribute_hidden;
194
extern double __ieee754_acos(double) attribute_hidden;
195
extern double __ieee754_acosh(double) attribute_hidden;
196
extern double __ieee754_log(double) attribute_hidden;
197
extern double __ieee754_atanh(double) attribute_hidden;
198
extern double __ieee754_asin(double) attribute_hidden;
199
extern double __ieee754_atan2(double, double) attribute_hidden;
200
extern double __ieee754_exp(double) attribute_hidden;
201
extern double __ieee754_cosh(double) attribute_hidden;
202
extern double __ieee754_fmod(double, double) attribute_hidden;
203
extern double __ieee754_pow(double, double) attribute_hidden;
204
extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
205
extern double __ieee754_gamma_r(double, int *) attribute_hidden;
206
extern double __ieee754_lgamma(double) attribute_hidden;
207
extern double __ieee754_gamma(double) attribute_hidden;
208
extern double __ieee754_log10(double) attribute_hidden;
209
extern double __ieee754_sinh(double) attribute_hidden;
210
extern double __ieee754_hypot(double, double) attribute_hidden;
211
extern double __ieee754_j0(double) attribute_hidden;
212
extern double __ieee754_j1(double) attribute_hidden;
213
extern double __ieee754_y0(double) attribute_hidden;
214
extern double __ieee754_y1(double) attribute_hidden;
215
extern double __ieee754_jn(int, double) attribute_hidden;
216
extern double __ieee754_yn(int, double) attribute_hidden;
217
extern double __ieee754_remainder(double, double) attribute_hidden;
218
extern int32_t __ieee754_rem_pio2(double, double *) attribute_hidden;
219
#if defined(_SCALB_INT)
220
extern double __ieee754_scalb(double, int) attribute_hidden;
221
#else
222
extern double __ieee754_scalb(double, double) attribute_hidden;
223
#endif
224
225
/* fdlibm kernel function */
226
#ifndef _IEEE_LIBM
227
extern double __kernel_standard(double, double, int) attribute_hidden;
228
#endif
229
extern double __kernel_sin(double, double, int) attribute_hidden;
230
extern double __kernel_cos(double, double) attribute_hidden;
231
extern double __kernel_tan(double, double, int) attribute_hidden;
232
extern int32_t __kernel_rem_pio2(const double *, double *, int, int, const unsigned int, const int32_t *) attribute_hidden;
233
234
#endif /* _MATH_PRIVATE_H_ */
235
236