gsl_complex.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* complex/gsl_complex.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __GSL_COMPLEX_H__
  20. #define __GSL_COMPLEX_H__
  21. #undef __BEGIN_DECLS
  22. #undef __END_DECLS
  23. #ifdef __cplusplus
  24. # define __BEGIN_DECLS extern "C" {
  25. # define __END_DECLS }
  26. #else
  27. # define __BEGIN_DECLS /* empty */
  28. # define __END_DECLS /* empty */
  29. #endif
  30. __BEGIN_DECLS
  31. /* two consecutive built-in types as a complex number */
  32. typedef double * gsl_complex_packed ;
  33. typedef float * gsl_complex_packed_float ;
  34. typedef long double * gsl_complex_packed_long_double ;
  35. typedef const double * gsl_const_complex_packed ;
  36. typedef const float * gsl_const_complex_packed_float ;
  37. typedef const long double * gsl_const_complex_packed_long_double ;
  38. /* 2N consecutive built-in types as N complex numbers */
  39. typedef double * gsl_complex_packed_array ;
  40. typedef float * gsl_complex_packed_array_float ;
  41. typedef long double * gsl_complex_packed_array_long_double ;
  42. typedef const double * gsl_const_complex_packed_array ;
  43. typedef const float * gsl_const_complex_packed_array_float ;
  44. typedef const long double * gsl_const_complex_packed_array_long_double ;
  45. /* Yes... this seems weird. Trust us. The point is just that
  46. sometimes you want to make it obvious that something is
  47. an output value. The fact that it lacks a 'const' may not
  48. be enough of a clue for people in some contexts.
  49. */
  50. typedef double * gsl_complex_packed_ptr ;
  51. typedef float * gsl_complex_packed_float_ptr ;
  52. typedef long double * gsl_complex_packed_long_double_ptr ;
  53. typedef const double * gsl_const_complex_packed_ptr ;
  54. typedef const float * gsl_const_complex_packed_float_ptr ;
  55. typedef const long double * gsl_const_complex_packed_long_double_ptr ;
  56. typedef struct
  57. {
  58. long double dat[2];
  59. }
  60. gsl_complex_long_double;
  61. typedef struct
  62. {
  63. double dat[2];
  64. }
  65. gsl_complex;
  66. typedef struct
  67. {
  68. float dat[2];
  69. }
  70. gsl_complex_float;
  71. #define GSL_REAL(z) ((z).dat[0])
  72. #define GSL_IMAG(z) ((z).dat[1])
  73. #define GSL_COMPLEX_P(zp) ((zp)->dat)
  74. #define GSL_COMPLEX_P_REAL(zp) ((zp)->dat[0])
  75. #define GSL_COMPLEX_P_IMAG(zp) ((zp)->dat[1])
  76. #define GSL_COMPLEX_EQ(z1,z2) (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))
  77. #define GSL_SET_COMPLEX(zp,x,y) do {(zp)->dat[0]=(x); (zp)->dat[1]=(y);} while(0)
  78. #define GSL_SET_REAL(zp,x) do {(zp)->dat[0]=(x);} while(0)
  79. #define GSL_SET_IMAG(zp,y) do {(zp)->dat[1]=(y);} while(0)
  80. #define GSL_SET_COMPLEX_PACKED(zp,n,x,y) do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)
  81. __END_DECLS
  82. #endif /* __GSL_COMPLEX_H__ */