xref: /illumos-gate/usr/src/lib/libm/common/complex/complex_wrapper.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24  */
25 /*
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef _COMPLEX_WRAPPER_H
31 #define	_COMPLEX_WRAPPER_H
32 
33 #if defined(__GNUC__)
34 #define dcomplex double _Complex
35 #define fcomplex float _Complex
36 #define ldcomplex long double _Complex
37 #define D_RE(x) __real__ x
38 #define D_IM(x) __imag__ x
39 #define F_RE(x) __real__ x
40 #define F_IM(x) __imag__ x
41 #define LD_RE(x) __real__ x
42 #define LD_IM(x) __imag__ x
43 
44 #include <complex.h>
45 #else
46 
47 #define	dcomplex	double complex
48 #define	fcomplex	float complex
49 #define	ldcomplex	long double complex
50 #define	_X_RE(__t, __z)	((__t *) &__z)[0]
51 #define	_X_IM(__t, __z)	((__t *) &__z)[1]
52 #define	D_RE(__z)	_X_RE(double, __z)
53 #define	D_IM(__z)	_X_IM(double, __z)
54 #define	F_RE(__z)	_X_RE(float, __z)
55 #define	F_IM(__z)	_X_IM(float, __z)
56 #define	LD_RE(__z)	_X_RE(long double, __z)
57 #define	LD_IM(__z)	_X_IM(long double, __z)
58 
59 #include <complex.h>
60 #endif
61 
62 #if defined(__sparc)
63 #define	HIWORD	0
64 #define	LOWORD	1
65 #define	HI_XWORD(x)	((unsigned *) &x)[0]
66 #define	XFSCALE(x, n)	((unsigned *) &x)[0] += n << 16	/* signbitl(x) == 0 */
67 #define	CHOPPED(x)	((long double) ((double) (x)))
68 #elif defined(__x86)
69 #define	HIWORD	1
70 #define	LOWORD	0
71 #define	HI_XWORD(x)	((((int *) &x)[2] << 16) | \
72 			(0xffff & ((unsigned *) &x)[1] >> 15))
73 #define	XFSCALE(x, n)	((unsigned short *) &x)[4] += n	/* signbitl(x) == 0 */
74 #define	CHOPPED(x)	((long double) ((float) (x)))
75 #else
76 #error Unknown architecture
77 #endif
78 #define	HI_WORD(x)	((int *) &x)[HIWORD]	/* for double */
79 #define	LO_WORD(x)	((int *) &x)[LOWORD]	/* for double */
80 #define	THE_WORD(x)	((int *) &x)[0]		/* for float */
81 
82 /*
83  * iy:ly must have the sign bit already cleared
84  */
85 #define	ISINF(iy, ly)	(((iy - 0x7ff00000) | ly) == 0)
86 
87 #endif	/* _COMPLEX_WRAPPER_H */
88