Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:00:54

0001 /* complex/gsl_complex.h
0002  * 
0003  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
0004  * Copyright (C) 2020, 2021 Patrick Alken
0005  * 
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 3 of the License, or (at
0009  * your option) any later version.
0010  * 
0011  * This program is distributed in the hope that it will be useful, but
0012  * WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * General Public License for more details.
0015  * 
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef __GSL_COMPLEX_H__
0022 #define __GSL_COMPLEX_H__
0023 
0024 #undef __BEGIN_DECLS
0025 #undef __END_DECLS
0026 #ifdef __cplusplus
0027 # define __BEGIN_DECLS extern "C" {
0028 # define __END_DECLS }
0029 #else
0030 # define __BEGIN_DECLS /* empty */
0031 # define __END_DECLS /* empty */
0032 #endif
0033 
0034 __BEGIN_DECLS
0035 
0036 
0037 /* two consecutive built-in types as a complex number */
0038 typedef double *       gsl_complex_packed ;
0039 typedef float *        gsl_complex_packed_float  ;
0040 typedef long double *  gsl_complex_packed_long_double ;
0041 
0042 typedef const double *       gsl_const_complex_packed ;
0043 typedef const float *        gsl_const_complex_packed_float  ;
0044 typedef const long double *  gsl_const_complex_packed_long_double ;
0045 
0046 
0047 /* 2N consecutive built-in types as N complex numbers */
0048 typedef double *       gsl_complex_packed_array ;
0049 typedef float *        gsl_complex_packed_array_float  ;
0050 typedef long double *  gsl_complex_packed_array_long_double ;
0051 
0052 typedef const double *       gsl_const_complex_packed_array ;
0053 typedef const float *        gsl_const_complex_packed_array_float  ;
0054 typedef const long double *  gsl_const_complex_packed_array_long_double ;
0055 
0056 
0057 /* Yes... this seems weird. Trust us. The point is just that
0058    sometimes you want to make it obvious that something is
0059    an output value. The fact that it lacks a 'const' may not
0060    be enough of a clue for people in some contexts.
0061  */
0062 typedef double *       gsl_complex_packed_ptr ;
0063 typedef float *        gsl_complex_packed_float_ptr  ;
0064 typedef long double *  gsl_complex_packed_long_double_ptr ;
0065 
0066 typedef const double *       gsl_const_complex_packed_ptr ;
0067 typedef const float *        gsl_const_complex_packed_float_ptr  ;
0068 typedef const long double *  gsl_const_complex_packed_long_double_ptr ;
0069 
0070 /*
0071  * If <complex.h> is included, use the C99 complex type.  Otherwise
0072  * define a type bit-compatible with C99 complex. The GSL_REAL and GSL_IMAG
0073  * macros require C11 functionality also (_Generic)
0074  */
0075 
0076 /* older gcc compilers claim to be C11 compliant but do not support _Generic */
0077 #if defined(__GNUC__) && (__GNUC__ < 7)
0078 #  define GSL_COMPLEX_LEGACY 1
0079 #endif
0080 
0081 #if !defined(GSL_COMPLEX_LEGACY) &&          \
0082      defined(_Complex_I) &&                  \
0083      defined(complex) &&                     \
0084      defined(I) &&                           \
0085      defined(__STDC__) && (__STDC__ == 1) && \
0086      defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
0087 
0088 #  define GSL_COMPLEX_DEFINE(R, C) typedef R _Complex C ;
0089 
0090 #  define GSL_COMPLEX_P(zp)        (&(zp))
0091 #  define GSL_COMPLEX_EQ(z1,z2)    ((z1) == (z2))
0092 #  define GSL_SET_COMPLEX(zp,x,y)  (*(zp) = (x) + I * (y))
0093 
0094 #  define GSL_REAL(z)              (_Generic((z),                             \
0095                                      complex float       : ((float *) &(z)),  \
0096                                      complex double      : ((double *) &(z)), \
0097                                      complex long double : ((long double *) &(z)))[0])
0098 
0099 #  define GSL_IMAG(z)              (_Generic((z),                             \
0100                                      complex float       : ((float *) &(z)),  \
0101                                      complex double      : ((double *) &(z)), \
0102                                      complex long double : ((long double *) &(z)))[1])
0103 
0104 #  define GSL_COMPLEX_P_REAL(zp)   GSL_REAL(*(zp))
0105 #  define GSL_COMPLEX_P_IMAG(zp)   GSL_IMAG(*(zp))
0106 #  define GSL_SET_REAL(zp,x)       do { GSL_REAL(*(zp)) = (x); } while(0)
0107 #  define GSL_SET_IMAG(zp,x)       do { GSL_IMAG(*(zp)) = (x); } while(0)
0108 
0109 #else /* legacy complex definitions */
0110 
0111 /*
0112  * According to the C17 standard, 6.2.5 paragraph 13:
0113  *
0114  * "Each complex type has the same representation and alignment requirements
0115  * as an array type containing exactly two elements of the corresponding real
0116  * type; the first element is equal to the real part, and the second element to
0117  * the imaginary part, of the complex number."
0118  */
0119 
0120 /*#  define GSL_COMPLEX_DEFINE(R, C) typedef R C[2]*/
0121 #  define GSL_COMPLEX_DEFINE(R, C) typedef struct { R dat[2]; } C ;
0122 
0123 #  define GSL_REAL(z)              ((z).dat[0])
0124 #  define GSL_IMAG(z)              ((z).dat[1])
0125 #  define GSL_COMPLEX_P(zp)        ((zp)->dat)
0126 #  define GSL_COMPLEX_P_REAL(zp)   ((zp)->dat[0])
0127 #  define GSL_COMPLEX_P_IMAG(zp)   ((zp)->dat[1])
0128 #  define GSL_COMPLEX_EQ(z1,z2)    (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))
0129 
0130 #  define GSL_SET_COMPLEX(zp,x,y)  do {(zp)->dat[0]=(x); (zp)->dat[1]=(y);} while(0)
0131 #  define GSL_SET_REAL(zp,x)       do {(zp)->dat[0]=(x);} while(0)
0132 #  define GSL_SET_IMAG(zp,y)       do {(zp)->dat[1]=(y);} while(0)
0133 
0134 #endif
0135 
0136 GSL_COMPLEX_DEFINE(double, gsl_complex)
0137 GSL_COMPLEX_DEFINE(long double, gsl_complex_long_double)
0138 GSL_COMPLEX_DEFINE(float, gsl_complex_float)
0139 
0140 #define GSL_SET_COMPLEX_PACKED(zp,n,x,y) do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)
0141 
0142 __END_DECLS
0143 
0144 #endif /* __GSL_COMPLEX_H__ */