Skip to content

Commit d4555b6

Browse files
committed
Merge pull request #46 from JuliaLang/cpack
Move complex number declarations to openlibm.h
2 parents 5f4979e + 3e769e4 commit d4555b6

File tree

5 files changed

+84
-80
lines changed

5 files changed

+84
-80
lines changed

src/math_private.h

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -227,86 +227,6 @@ do { \
227227
* Common routine to process the arguments to nan(), nanf(), and nanl().
228228
*/
229229
void _scan_nan(u_int32_t *__words, int __num_words, const char *__s);
230-
231-
//VBS
232-
//#ifdef _COMPLEX_H
233-
234-
/*
235-
* C99 specifies that complex numbers have the same representation as
236-
* an array of two elements, where the first element is the real part
237-
* and the second element is the imaginary part.
238-
*/
239-
typedef union {
240-
float complex f;
241-
float a[2];
242-
} float_complex;
243-
typedef union {
244-
double complex f;
245-
double a[2];
246-
} double_complex;
247-
typedef union {
248-
long double complex f;
249-
long double a[2];
250-
} long_double_complex;
251-
#define REALPART(z) ((z).a[0])
252-
#define IMAGPART(z) ((z).a[1])
253-
254-
/*
255-
* Inline functions that can be used to construct complex values.
256-
*
257-
* The C99 standard intends x+I*y to be used for this, but x+I*y is
258-
* currently unusable in general since gcc introduces many overflow,
259-
* underflow, sign and efficiency bugs by rewriting I*y as
260-
* (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
261-
* In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
262-
* to -0.0+I*0.0.
263-
*
264-
* In C11, a CMPLX(x,y) macro was added to circumvent this limitation,
265-
* and gcc 4.7 added a __builtin_complex feature to simplify implementation
266-
* of CMPLX in libc, so we can take advantage of these features if they
267-
* are available.
268-
*/
269-
#if defined(CMPLXF) && defined(CMPLX) && defined(CMPLXL) /* C11 */
270-
# define cpackf(x,y) CMPLXF(x,y)
271-
# define cpack(x,y) CMPLX(x,y)
272-
# define cpackl(x,y) CMPLXL(x,y)
273-
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__INTEL_COMPILER)
274-
# define cpackf(x,y) __builtin_complex ((float) (x), (float) (y))
275-
# define cpack(x,y) __builtin_complex ((double) (x), (double) (y))
276-
# define cpackl(x,y) __builtin_complex ((long double) (x), (long double) (y))
277-
#else /* define our own cpack functions */
278-
static __inline float complex
279-
cpackf(float x, float y)
280-
{
281-
float_complex z;
282-
283-
REALPART(z) = x;
284-
IMAGPART(z) = y;
285-
return (z.f);
286-
}
287-
288-
static __inline double complex
289-
cpack(double x, double y)
290-
{
291-
double_complex z;
292-
293-
REALPART(z) = x;
294-
IMAGPART(z) = y;
295-
return (z.f);
296-
}
297-
298-
static __inline long double complex
299-
cpackl(long double x, long double y)
300-
{
301-
long_double_complex z;
302-
303-
REALPART(z) = x;
304-
IMAGPART(z) = y;
305-
return (z.f);
306-
}
307-
#endif /* define our own cpack functions */
308-
//VBS
309-
//#endif /* _COMPLEX_H */
310230

311231
#ifdef __GNUCLIKE_ASM
312232

src/openlibm.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef _MATH_H_
1818
#define _MATH_H_
1919

20+
#include <complex.h>
2021
#include "cdefs-compat.h"
2122
#include "types-compat.h"
2223

@@ -167,6 +168,86 @@ extern int signgam;
167168
#endif
168169
#endif /* __BSD_VISIBLE */
169170

171+
//VBS
172+
//#ifdef _COMPLEX_H
173+
174+
/*
175+
* C99 specifies that complex numbers have the same representation as
176+
* an array of two elements, where the first element is the real part
177+
* and the second element is the imaginary part.
178+
*/
179+
typedef union {
180+
float complex f;
181+
float a[2];
182+
} float_complex;
183+
typedef union {
184+
double complex f;
185+
double a[2];
186+
} double_complex;
187+
typedef union {
188+
long double complex f;
189+
long double a[2];
190+
} long_double_complex;
191+
#define REALPART(z) ((z).a[0])
192+
#define IMAGPART(z) ((z).a[1])
193+
194+
/*
195+
* Inline functions that can be used to construct complex values.
196+
*
197+
* The C99 standard intends x+I*y to be used for this, but x+I*y is
198+
* currently unusable in general since gcc introduces many overflow,
199+
* underflow, sign and efficiency bugs by rewriting I*y as
200+
* (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
201+
* In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
202+
* to -0.0+I*0.0.
203+
*
204+
* In C11, a CMPLX(x,y) macro was added to circumvent this limitation,
205+
* and gcc 4.7 added a __builtin_complex feature to simplify implementation
206+
* of CMPLX in libc, so we can take advantage of these features if they
207+
* are available.
208+
*/
209+
#if defined(CMPLXF) && defined(CMPLX) && defined(CMPLXL) /* C11 */
210+
# define cpackf(x,y) CMPLXF(x,y)
211+
# define cpack(x,y) CMPLX(x,y)
212+
# define cpackl(x,y) CMPLXL(x,y)
213+
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__INTEL_COMPILER)
214+
# define cpackf(x,y) __builtin_complex ((float) (x), (float) (y))
215+
# define cpack(x,y) __builtin_complex ((double) (x), (double) (y))
216+
# define cpackl(x,y) __builtin_complex ((long double) (x), (long double) (y))
217+
#else /* define our own cpack functions */
218+
static __inline float complex
219+
cpackf(float x, float y)
220+
{
221+
float_complex z;
222+
223+
REALPART(z) = x;
224+
IMAGPART(z) = y;
225+
return (z.f);
226+
}
227+
228+
static __inline double complex
229+
cpack(double x, double y)
230+
{
231+
double_complex z;
232+
233+
REALPART(z) = x;
234+
IMAGPART(z) = y;
235+
return (z.f);
236+
}
237+
238+
static __inline long double complex
239+
cpackl(long double x, long double y)
240+
{
241+
long_double_complex z;
242+
243+
REALPART(z) = x;
244+
IMAGPART(z) = y;
245+
return (z.f);
246+
}
247+
#endif /* define our own cpack functions */
248+
//VBS
249+
//#endif /* _COMPLEX_H */
250+
170251
/*
171252
* Most of these functions depend on the rounding mode and have the side
172253
* effect of raising floating-point exceptions, so they are not declared

src/s_cimag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include <complex.h>
30+
#include "openlibm.h"
3031
#include "math_private.h"
3132

3233
DLLEXPORT double

src/s_cimagf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include <complex.h>
30+
#include "openlibm.h"
3031
#include "math_private.h"
3132

3233
DLLEXPORT float

src/s_cimagl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include <complex.h>
30+
#include "openlibm.h"
3031
#include "math_private.h"
3132

3233
DLLEXPORT long double

0 commit comments

Comments
 (0)