Eliminate __real__ and __imag__ gccisms.

This commit is contained in:
das 2009-03-14 18:24:15 +00:00
parent 4cd01fc223
commit fa12b26b66
4 changed files with 42 additions and 15 deletions

View File

@ -190,6 +190,27 @@ do { \
void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
#ifdef _COMPLEX_H
/*
* C99 specifies that complex numbers have the same representation as
* an array of two elements, where the first element is the real part
* and the second element is the imaginary part.
*/
typedef union {
float complex f;
float a[2];
} float_complex;
typedef union {
double complex f;
double a[2];
} double_complex;
typedef union {
long double complex f;
long double a[2];
} long_double_complex;
#define REALPART(z) ((z).a[0])
#define IMAGPART(z) ((z).a[1])
/*
* Inline functions that can be used to construct complex values.
*
@ -203,31 +224,31 @@ void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
static __inline float complex
cpackf(float x, float y)
{
float complex z;
float_complex z;
__real__ z = x;
__imag__ z = y;
return (z);
REALPART(z) = x;
IMAGPART(z) = y;
return (z.f);
}
static __inline double complex
cpack(double x, double y)
{
double complex z;
double_complex z;
__real__ z = x;
__imag__ z = y;
return (z);
REALPART(z) = x;
IMAGPART(z) = y;
return (z.f);
}
static __inline long double complex
cpackl(long double x, long double y)
{
long double complex z;
long_double_complex z;
__real__ z = x;
__imag__ z = y;
return (z);
REALPART(z) = x;
IMAGPART(z) = y;
return (z.f);
}
#endif /* _COMPLEX_H */

View File

@ -27,10 +27,12 @@
*/
#include <complex.h>
#include "math_private.h"
double
cimag(double complex z)
{
const double_complex z1 = { .f = z };
return (__imag__ z);
return (IMAGPART(z1));
}

View File

@ -27,10 +27,12 @@
*/
#include <complex.h>
#include "math_private.h"
float
cimagf(float complex z)
{
const float_complex z1 = { .f = z };
return (__imag__ z);
return (IMAGPART(z1));
}

View File

@ -27,10 +27,12 @@
*/
#include <complex.h>
#include "math_private.h"
long double
cimagl(long double complex z)
{
const long_double_complex z1 = { .f = z };
return (__imag__ z);
return (IMAGPART(z1));
}