1 /*! \file
2 Copyright (c) 2003, The Regents of the University of California, through
3 Lawrence Berkeley National Laboratory (subject to receipt of any required
4 approvals from U.S. Dept. of Energy)
5 
6 All rights reserved.
7 
8 The source code is distributed under BSD license, see the file License.txt
9 at the top-level directory.
10 */
11 
12 /*! @file slu_scomplex.h
13  * \brief Header file for complex operations
14  * <pre>
15  *  -- SuperLU routine (version 2.0) --
16  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
17  * and Lawrence Berkeley National Lab.
18  * November 15, 1997
19  *
20  * Contains definitions for various complex operations.
21  * This header file is to be included in source files c*.c
22  * </pre>
23  */
24 #ifndef __SUPERLU_SCOMPLEX /* allow multiple inclusions */
25 #define __SUPERLU_SCOMPLEX
26 
27 
28 #ifndef SCOMPLEX_INCLUDE
29 #define SCOMPLEX_INCLUDE
30 
31 typedef struct { float r, i; } complex;
32 
33 
34 /* Macro definitions */
35 
36 /*! \brief Complex Addition c = a + b */
37 #define c_add(c, a, b) { (c)->r = (a)->r + (b)->r; \
38 			 (c)->i = (a)->i + (b)->i; }
39 
40 /*! \brief Complex Subtraction c = a - b */
41 #define c_sub(c, a, b) { (c)->r = (a)->r - (b)->r; \
42 			 (c)->i = (a)->i - (b)->i; }
43 
44 /*! \brief Complex-Double Multiplication */
45 #define cs_mult(c, a, b) { (c)->r = (a)->r * (b); \
46                            (c)->i = (a)->i * (b); }
47 
48 /*! \brief Complex-Complex Multiplication */
49 #define cc_mult(c, a, b) { \
50 	float cr, ci; \
51     	cr = (a)->r * (b)->r - (a)->i * (b)->i; \
52     	ci = (a)->i * (b)->r + (a)->r * (b)->i; \
53     	(c)->r = cr; \
54     	(c)->i = ci; \
55     }
56 
57 #define cc_conj(a, b) { \
58         (a)->r = (b)->r; \
59         (a)->i = -((b)->i); \
60     }
61 
62 /*! \brief Complex equality testing */
63 #define c_eq(a, b)  ( (a)->r == (b)->r && (a)->i == (b)->i )
64 
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 /* Prototypes for functions in scomplex.c */
71 void c_div(complex *, complex *, complex *);
72 double c_abs(complex *);     /* exact */
73 double c_abs1(complex *);    /* approximate */
74 void c_exp(complex *, complex *);
75 void r_cnjg(complex *, complex *);
76 double r_imag(complex *);
77 complex c_sgn(complex *);
78 complex c_sqrt(complex *);
79 
80 
81 
82 #ifdef __cplusplus
83   }
84 #endif
85 
86 #endif
87 
88 #endif  /* __SUPERLU_SCOMPLEX */
89