enable complex in libm.h
[libm] / src / internal / libm.h
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 #include <stdint.h>
17 #include <float.h>
18 #include <math.h>
19 #include <complex.h>
20
21 // FIXME
22 #include "ldhack.h"
23
24 union fshape {
25         float value;
26         uint32_t bits;
27 };
28
29 union dshape {
30         double value;
31         uint64_t bits;
32 };
33
34 /* Get two 32 bit ints from a double.  */
35 #define EXTRACT_WORDS(hi,lo,d)                                  \
36 do {                                                            \
37   union dshape __u;                                             \
38   __u.value = (d);                                              \
39   (hi) = __u.bits >> 32;                                        \
40   (lo) = (uint32_t)__u.bits;                                    \
41 } while (0)
42
43 /* Get a 64 bit int from a double.  */
44 #define EXTRACT_WORD64(i,d)                                     \
45 do {                                                            \
46   union dshape __u;                                             \
47   __u.value = (d);                                              \
48   (i) = __u.bits;                                               \
49 } while (0)
50
51 /* Get the more significant 32 bit int from a double.  */
52 #define GET_HIGH_WORD(i,d)                                      \
53 do {                                                            \
54   union dshape __u;                                             \
55   __u.value = (d);                                              \
56   (i) = __u.bits >> 32;                                         \
57 } while (0)
58
59 /* Get the less significant 32 bit int from a double.  */
60 #define GET_LOW_WORD(i,d)                                       \
61 do {                                                            \
62   union dshape __u;                                             \
63   __u.value = (d);                                              \
64   (i) = (uint32_t)__u.bits;                                     \
65 } while (0)
66
67 /* Set a double from two 32 bit ints.  */
68 #define INSERT_WORDS(d,hi,lo)                                   \
69 do {                                                            \
70   union dshape __u;                                             \
71   __u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo);           \
72   (d) = __u.value;                                              \
73 } while (0)
74
75 /* Set a double from a 64 bit int.  */
76 #define INSERT_WORD64(d,i)                                      \
77 do {                                                            \
78   union dshape __u;                                             \
79   __u.bits = (i);                                               \
80   (d) = __u.value;                                              \
81 } while (0)
82
83 /* Set the more significant 32 bits of a double from an int.  */
84 #define SET_HIGH_WORD(d,hi)                                     \
85 do {                                                            \
86   union dshape __u;                                             \
87   __u.value = (d);                                              \
88   __u.bits &= 0xffffffff;                                       \
89   __u.bits |= (uint64_t)(hi) << 32;                             \
90   (d) = __u.value;                                              \
91 } while (0)
92
93 /* Set the less significant 32 bits of a double from an int.  */
94 #define SET_LOW_WORD(d,lo)                                      \
95 do {                                                            \
96   union dshape __u;                                             \
97   __u.value = (d);                                              \
98   __u.bits &= 0xffffffff00000000ull;                            \
99   __u.bits |= (uint32_t)(lo);                                   \
100   (d) = __u.value;                                              \
101 } while (0)
102
103 /* Get a 32 bit int from a float.  */
104 #define GET_FLOAT_WORD(i,d)                                     \
105 do {                                                            \
106   union fshape __u;                                             \
107   __u.value = (d);                                              \
108   (i) = __u.bits;                                               \
109 } while (0)
110
111 /* Set a float from a 32 bit int.  */
112 #define SET_FLOAT_WORD(d,i)                                     \
113 do {                                                            \
114   union fshape __u;                                             \
115   __u.bits = (i);                                               \
116   (d) = __u.value;                                              \
117 } while (0)
118
119 /* fdlibm kernel functions */
120 int    __rem_pio2_large(double*,double*,int,int,int);
121
122 int    __rem_pio2(double,double*);
123 double __sin(double,double,int);
124 double __cos(double,double);
125 double __tan(double,double,int);
126 double __ldexp_exp(double,int);
127 #if 0
128 double complex __ldexp_cexp(double complex,int);
129 #endif
130
131 int    __rem_pio2f(float,double*);
132 float  __sindf(double);
133 float  __cosdf(double);
134 float  __tandf(double,int);
135 float  __ldexp_expf(float,int);
136 #if 0
137 float complex __ldexp_cexpf(float complex,int);
138 #endif
139
140 /* long double precision kernel functions */
141 long double __sinl(long double, long double, int);
142 long double __cosl(long double, long double);
143 long double __tanl(long double, long double, int);
144
145 /* polynomial evaluation */
146 long double __polevll(long double, long double *, int);
147 long double __p1evll(long double, long double *, int);
148
149 // FIXME: nan
150 /*
151  * Common routine to process the arguments to nan(), nanf(), and nanl().
152  */
153 void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
154
155 // FIXME: not needed when -fexcess-precision=standard is supported (>=gcc4.5)
156 /*
157  * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
158  */
159 #if 1
160 #define STRICT_ASSIGN(type, lval, rval) do {    \
161         volatile type __v = (rval);             \
162         (lval) = __v;                           \
163 } while (0)
164 #else
165 #define STRICT_ASSIGN(type, lval, rval) ((lval) = (type)(rval))
166 #endif
167
168
169 /* complex */
170
171 union dcomplex {
172         double complex z;
173         double a[2];
174 };
175 union fcomplex {
176         float complex z;
177         float a[2];
178 };
179 union lcomplex {
180         long double complex z;
181         long double a[2];
182 };
183
184 // FIXME: move to complex.h ?
185 #define creal(z) ((double)(z))
186 #define crealf(z) ((float)(z))
187 #define creall(z) ((long double)(z))
188 #define cimag(z) ((union dcomplex){(z)}.a[1])
189 #define cimagf(z) ((union fcomplex){(z)}.a[1])
190 #define cimagl(z) ((union lcomplex){(z)}.a[1])
191
192 /* x + y*I is not supported properly by gcc */
193 #define cpack(x,y) ((union dcomplex){.a={(x),(y)}}.z)
194 #define cpackf(x,y) ((union fcomplex){.a={(x),(y)}}.z)
195 #define cpackl(x,y) ((union lcomplex){.a={(x),(y)}}.z)
196
197 #endif