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 /*
  27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #ifndef _COMPLEX_WRAPPER_H
  32 #define _COMPLEX_WRAPPER_H
  33 
  34 #pragma ident   "@(#)complex_wrapper.h  1.7     06/01/31 SMI"
  35 
  36 #if defined(__GNUC__)
  37 #define dcomplex                double _Complex
  38 #define fcomplex                float _Complex
  39 #define ldcomplex               long double _Complex
  40 #define D_RE(x)                 __real__ x
  41 #define D_IM(x)                 __imag__ x
  42 #define F_RE(x)                 __real__ x
  43 #define F_IM(x)                 __imag__ x
  44 #define LD_RE(x)                __real__ x
  45 #define LD_IM(x)                __imag__ x
  46 
  47 #include <complex.h>
  48 #else
  49 #define dcomplex                double complex
  50 #define fcomplex                float complex
  51 #define ldcomplex               long double complex
  52 #define _X_RE(__t, __z)         ((__t *)&__z)[0]
  53 #define _X_IM(__t, __z)         ((__t *)&__z)[1]
  54 #define D_RE(__z)               _X_RE(double, __z)
  55 #define D_IM(__z)               _X_IM(double, __z)
  56 #define F_RE(__z)               _X_RE(float, __z)
  57 #define F_IM(__z)               _X_IM(float, __z)
  58 #define LD_RE(__z)              _X_RE(long double, __z)
  59 #define LD_IM(__z)              _X_IM(long double, __z)
  60 
  61 #include <complex.h>
  62 #endif
  63 
  64 #if defined(__sparc)
  65 #define HIWORD          0
  66 #define LOWORD          1
  67 #define HI_XWORD(x)     ((unsigned *)&x)[0]
  68 #define XFSCALE(x, n)   ((unsigned *)&x)[0] += n << 16        /* signbitl(x) == 0 */
  69 #define CHOPPED(x)      ((long double)((double)(x)))
  70 #elif defined(__x86)
  71 #define HIWORD          1
  72 #define LOWORD          0
  73 #define HI_XWORD(x)     ((((int *)&x)[2] << 16) | (0xffff & \
  74         ((unsigned *)&x)[1] >> 15))
  75 #define XFSCALE(x, n)   ((unsigned short *)&x)[4] += n      /* signbitl(x) == 0 */
  76 #define CHOPPED(x)      ((long double)((float)(x)))
  77 #else
  78 #error Unknown architecture
  79 #endif
  80 #define HI_WORD(x)              ((int *)&x)[HIWORD] /* for double */
  81 #define LO_WORD(x)              ((int *)&x)[LOWORD] /* for double */
  82 #define THE_WORD(x)             ((int *)&x)[0]              /* for float */
  83 
  84 /*
  85  * iy:ly must have the sign bit already cleared
  86  */
  87 #define ISINF(iy, ly)           (((iy - 0x7ff00000) | ly) == 0)
  88 #endif /* _COMPLEX_WRAPPER_H */