/* This is a small test case for returning a complex number. Written by
|
/* This is a small test case for returning a complex number. Written by
|
Andreas Jaeger. */
|
Andreas Jaeger. */
|
|
|
#include "defines.h"
|
#include "defines.h"
|
|
|
|
|
#define BUILD_F_COMPLEX(real, imag) \
|
#define BUILD_F_COMPLEX(real, imag) \
|
({ __complex__ float __retval; \
|
({ __complex__ float __retval; \
|
__real__ __retval = (real); \
|
__real__ __retval = (real); \
|
__imag__ __retval = (imag); \
|
__imag__ __retval = (imag); \
|
__retval; })
|
__retval; })
|
|
|
#define BUILD_D_COMPLEX(real, imag) \
|
#define BUILD_D_COMPLEX(real, imag) \
|
({ __complex__ double __retval; \
|
({ __complex__ double __retval; \
|
__real__ __retval = (real); \
|
__real__ __retval = (real); \
|
__imag__ __retval = (imag); \
|
__imag__ __retval = (imag); \
|
__retval; })
|
__retval; })
|
|
|
#define BUILD_LD_COMPLEX(real, imag) \
|
#define BUILD_LD_COMPLEX(real, imag) \
|
({ __complex__ long double __retval; \
|
({ __complex__ long double __retval; \
|
__real__ __retval = (real); \
|
__real__ __retval = (real); \
|
__imag__ __retval = (imag); \
|
__imag__ __retval = (imag); \
|
__retval; })
|
__retval; })
|
|
|
__complex__ float
|
__complex__ float
|
aj_f_times2 (__complex__ float x)
|
aj_f_times2 (__complex__ float x)
|
{
|
{
|
__complex__ float res;
|
__complex__ float res;
|
|
|
__real__ res = (2.0 * __real__ x);
|
__real__ res = (2.0 * __real__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
|
|
return res;
|
return res;
|
}
|
}
|
|
|
__complex__ double
|
__complex__ double
|
aj_d_times2 (__complex__ double x)
|
aj_d_times2 (__complex__ double x)
|
{
|
{
|
__complex__ double res;
|
__complex__ double res;
|
|
|
__real__ res = (2.0 * __real__ x);
|
__real__ res = (2.0 * __real__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
|
|
return res;
|
return res;
|
}
|
}
|
|
|
__complex__ long double
|
__complex__ long double
|
aj_ld_times2 (__complex__ long double x)
|
aj_ld_times2 (__complex__ long double x)
|
{
|
{
|
__complex__ long double res;
|
__complex__ long double res;
|
|
|
__real__ res = (2.0 * __real__ x);
|
__real__ res = (2.0 * __real__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
__imag__ res = (2.0 * __imag__ x);
|
|
|
return res;
|
return res;
|
}
|
}
|
|
|
int
|
int
|
main (void)
|
main (void)
|
{
|
{
|
#ifdef CHECK_COMPLEX
|
#ifdef CHECK_COMPLEX
|
_Complex float fc, fd;
|
_Complex float fc, fd;
|
_Complex double dc, dd;
|
_Complex double dc, dd;
|
_Complex long double ldc, ldd;
|
_Complex long double ldc, ldd;
|
|
|
fc = BUILD_LD_COMPLEX (2.0f, 3.0f);
|
fc = BUILD_LD_COMPLEX (2.0f, 3.0f);
|
fd = aj_f_times2 (fc);
|
fd = aj_f_times2 (fc);
|
|
|
assert (__real__ fd == 4.0f && __imag__ fd == 6.0f);
|
assert (__real__ fd == 4.0f && __imag__ fd == 6.0f);
|
|
|
dc = BUILD_LD_COMPLEX (2.0, 3.0);
|
dc = BUILD_LD_COMPLEX (2.0, 3.0);
|
dd = aj_ld_times2 (dc);
|
dd = aj_ld_times2 (dc);
|
|
|
assert (__real__ dd == 4.0 && __imag__ dd == 6.0);
|
assert (__real__ dd == 4.0 && __imag__ dd == 6.0);
|
|
|
ldc = BUILD_LD_COMPLEX (2.0L, 3.0L);
|
ldc = BUILD_LD_COMPLEX (2.0L, 3.0L);
|
ldd = aj_ld_times2 (ldc);
|
ldd = aj_ld_times2 (ldc);
|
|
|
assert (__real__ ldd == 4.0L && __imag__ ldd == 6.0L);
|
assert (__real__ ldd == 4.0L && __imag__ ldd == 6.0L);
|
#endif
|
#endif
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|