Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/compileincludes/libm.h
2 views
1
/* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
2
/*
3
* ====================================================
4
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
*
6
* Developed at SunPro, a Sun Microsystems, Inc. business.
7
* Permission to use, copy, modify, and distribute this
8
* software is freely granted, provided that this notice
9
* is preserved.
10
* ====================================================
11
*/
12
13
#ifndef _LIBM_H
14
#define _LIBM_H
15
16
#ifndef _GNU_SOURCE
17
#define _GNU_SOURCE
18
#endif
19
20
#include <stdint.h>
21
#include <float.h>
22
#include <math.h>
23
#include <complex.h>
24
#include <endian.h>
25
26
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
27
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
28
union ldshape {
29
long double f;
30
struct {
31
uint64_t m;
32
uint16_t se;
33
} i;
34
};
35
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
36
union ldshape {
37
long double f;
38
struct {
39
uint64_t lo;
40
uint32_t mid;
41
uint16_t top;
42
uint16_t se;
43
} i;
44
struct {
45
uint64_t lo;
46
uint64_t hi;
47
} i2;
48
};
49
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN
50
union ldshape {
51
long double f;
52
struct {
53
uint16_t se;
54
uint16_t top;
55
uint32_t mid;
56
uint64_t lo;
57
} i;
58
struct {
59
uint64_t hi;
60
uint64_t lo;
61
} i2;
62
};
63
#else
64
#error Unsupported long double representation
65
#endif
66
67
#define FORCE_EVAL(x) do { \
68
if (sizeof(x) == sizeof(float)) { \
69
volatile float __x; \
70
__x = (x); \
71
} else if (sizeof(x) == sizeof(double)) { \
72
volatile double __x; \
73
__x = (x); \
74
} else { \
75
volatile long double __x; \
76
__x = (x); \
77
} \
78
} while(0)
79
80
/* Get two 32 bit ints from a double. */
81
#define EXTRACT_WORDS(hi,lo,d) \
82
do { \
83
union {double f; uint64_t i;} __u; \
84
__u.f = (d); \
85
(hi) = __u.i >> 32; \
86
(lo) = (uint32_t)__u.i; \
87
} while (0)
88
89
/* Get the more significant 32 bit int from a double. */
90
#define GET_HIGH_WORD(hi,d) \
91
do { \
92
union {double f; uint64_t i;} __u; \
93
__u.f = (d); \
94
(hi) = __u.i >> 32; \
95
} while (0)
96
97
/* Get the less significant 32 bit int from a double. */
98
#define GET_LOW_WORD(lo,d) \
99
do { \
100
union {double f; uint64_t i;} __u; \
101
__u.f = (d); \
102
(lo) = (uint32_t)__u.i; \
103
} while (0)
104
105
/* Set a double from two 32 bit ints. */
106
#define INSERT_WORDS(d,hi,lo) \
107
do { \
108
union {double f; uint64_t i;} __u; \
109
__u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \
110
(d) = __u.f; \
111
} while (0)
112
113
/* Set the more significant 32 bits of a double from an int. */
114
#define SET_HIGH_WORD(d,hi) \
115
do { \
116
union {double f; uint64_t i;} __u; \
117
__u.f = (d); \
118
__u.i &= 0xffffffff; \
119
__u.i |= (uint64_t)(hi) << 32; \
120
(d) = __u.f; \
121
} while (0)
122
123
/* Set the less significant 32 bits of a double from an int. */
124
#define SET_LOW_WORD(d,lo) \
125
do { \
126
union {double f; uint64_t i;} __u; \
127
__u.f = (d); \
128
__u.i &= 0xffffffff00000000ull; \
129
__u.i |= (uint32_t)(lo); \
130
(d) = __u.f; \
131
} while (0)
132
133
/* Get a 32 bit int from a float. */
134
#define GET_FLOAT_WORD(w,d) \
135
do { \
136
union {float f; uint32_t i;} __u; \
137
__u.f = (d); \
138
(w) = __u.i; \
139
} while (0)
140
141
/* Set a float from a 32 bit int. */
142
#define SET_FLOAT_WORD(d,w) \
143
do { \
144
union {float f; uint32_t i;} __u; \
145
__u.i = (w); \
146
(d) = __u.f; \
147
} while (0)
148
149
#undef __CMPLX
150
#undef CMPLX
151
#undef CMPLXF
152
#undef CMPLXL
153
154
#define __CMPLX(x, y, t) \
155
((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z)
156
157
#define CMPLX(x, y) __CMPLX(x, y, double)
158
#define CMPLXF(x, y) __CMPLX(x, y, float)
159
#define CMPLXL(x, y) __CMPLX(x, y, long double)
160
161
/* fdlibm kernel functions */
162
163
int __rem_pio2_large(double*,double*,int,int,int);
164
165
int __rem_pio2(double,double*);
166
double __sin(double,double,int);
167
double __cos(double,double);
168
double __tan(double,double,int);
169
double __expo2(double);
170
double complex __ldexp_cexp(double complex,int);
171
172
int __rem_pio2f(float,double*);
173
float __sindf(double);
174
float __cosdf(double);
175
float __tandf(double,int);
176
float __expo2f(float);
177
float complex __ldexp_cexpf(float complex,int);
178
179
int __rem_pio2l(long double, long double *);
180
long double __sinl(long double, long double, int);
181
long double __cosl(long double, long double);
182
long double __tanl(long double, long double, int);
183
184
/* polynomial evaluation */
185
long double __polevll(long double, const long double *, int);
186
long double __p1evll(long double, const long double *, int);
187
188
#endif
189
190