Initial revision
[LeanCalc.git] / calc / calc / cmath.h
1 /*
2  * cmath - data structures for extended precision complex arithmetic
3  *
4  * Copyright (C) 1999  David I. Bell
5  *
6  * Calc is open software; you can redistribute it and/or modify it under
7  * the terms of the version 2.1 of the GNU Lesser General Public License
8  * as published by the Free Software Foundation.
9  *
10  * Calc is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13  * Public License for more details.
14  *
15  * A copy of version 2.1 of the GNU Lesser General Public License is
16  * distributed with calc under the filename COPYING-LGPL.  You should have
17  * received a copy with calc; if not, write to Free Software Foundation, Inc.
18  * 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * @(#) $Revision$
21  * @(#) $Id$
22  * @(#) $Source$
23  *
24  * Under source code control:   1993/07/30 19:42:45
25  * File existed as early as:    1993
26  *
27  * Share and enjoy!  :-)        http://www.isthe.com/chongo/tech/comp/calc/
28  */
29
30
31 #if !defined(__CMATH_H__)
32 #define __CMATH_H__
33
34
35 #if defined(CALC_SRC)   /* if we are building from the calc source tree */
36 # include "calc/qmath.h"
37 #else
38 # include <calc/qmath.h>
39 #endif
40
41
42 /*
43  * Complex arithmetic definitions.
44  */
45 typedef struct {
46         NUMBER *real;           /* real part of number */
47         NUMBER *imag;           /* imaginary part of number */
48         long links;             /* link count */
49 } COMPLEX;
50
51
52 /*
53  * Input, output, and conversion routines.
54  */
55 extern COMPLEX *comalloc(void);
56 extern COMPLEX *qqtoc(NUMBER *q1, NUMBER *q2);
57 extern void comfree(COMPLEX *c);
58 extern void comprint(COMPLEX *c);
59 extern void cprintfr(COMPLEX *c);
60
61
62 /*
63  * Basic numeric routines.
64  */
65
66 extern COMPLEX *cadd(COMPLEX *c1, COMPLEX *c2);
67 extern COMPLEX *csub(COMPLEX *c1, COMPLEX *c2);
68 extern COMPLEX *cmul(COMPLEX *c1, COMPLEX *c2);
69 extern COMPLEX *cdiv(COMPLEX *c1, COMPLEX *c2);
70 extern COMPLEX *caddq(COMPLEX *c, NUMBER *q);
71 extern COMPLEX *csubq(COMPLEX *c, NUMBER *q);
72 extern COMPLEX *cmulq(COMPLEX *c, NUMBER *q);
73 extern COMPLEX *cdivq(COMPLEX *c, NUMBER *q);
74 extern COMPLEX *cscale(COMPLEX *c, long i);
75 extern COMPLEX *cshift(COMPLEX *c, long i);
76 extern COMPLEX *csquare(COMPLEX *c);
77 extern COMPLEX *cconj(COMPLEX *c);
78 extern COMPLEX *c_real(COMPLEX *c);
79 extern COMPLEX *c_imag(COMPLEX *c);
80 extern COMPLEX *cneg(COMPLEX *c);
81 extern COMPLEX *cinv(COMPLEX *c);
82 extern COMPLEX *cint(COMPLEX *c);
83 extern COMPLEX *cfrac(COMPLEX *c);
84 extern BOOL ccmp(COMPLEX *c1, COMPLEX *c2);
85
86
87 /*
88  * More complicated functions.
89  */
90 extern COMPLEX *cpowi(COMPLEX *c, NUMBER *q);
91 extern NUMBER *cilog(COMPLEX *c, ZVALUE base);
92
93
94 /*
95  * Transcendental routines.  These all take an epsilon argument to
96  * specify how accurately these are to be calculated.
97  */
98 extern COMPLEX *cpower(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon);
99 extern COMPLEX *csqrt(COMPLEX *c, NUMBER *epsilon, long R);
100 extern COMPLEX *croot(COMPLEX *c, NUMBER *q, NUMBER *epsilon);
101 extern COMPLEX *cexp(COMPLEX *c, NUMBER *epsilon);
102 extern COMPLEX *cln(COMPLEX *c, NUMBER *epsilon);
103 extern COMPLEX *ccos(COMPLEX *c, NUMBER *epsilon);
104 extern COMPLEX *csin(COMPLEX *c, NUMBER *epsilon);
105 extern COMPLEX *ccosh(COMPLEX *c, NUMBER *epsilon);
106 extern COMPLEX *csinh(COMPLEX *c, NUMBER *epsilon);
107 extern COMPLEX *cpolar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon);
108 extern COMPLEX *crel(COMPLEX *c1, COMPLEX *c2);
109 extern COMPLEX *casin(COMPLEX *c, NUMBER *epsilon);
110 extern COMPLEX *cacos(COMPLEX *c, NUMBER *epsilon);
111 extern COMPLEX *catan(COMPLEX *c, NUMBER *epsilon);
112 extern COMPLEX *cacot(COMPLEX *c, NUMBER *epsilon);
113 extern COMPLEX *casec(COMPLEX *c, NUMBER *epsilon);
114 extern COMPLEX *cacsc(COMPLEX *c, NUMBER *epsilon);
115 extern COMPLEX *casinh(COMPLEX *c, NUMBER *epsilon);
116 extern COMPLEX *cacosh(COMPLEX *c, NUMBER *epsilon);
117 extern COMPLEX *catanh(COMPLEX *c, NUMBER *epsilon);
118 extern COMPLEX *cacoth(COMPLEX *c, NUMBER *epsilon);
119 extern COMPLEX *casech(COMPLEX *c, NUMBER *epsilon);
120 extern COMPLEX *cacsch(COMPLEX *c, NUMBER *epsilon);
121 extern COMPLEX *cgd(COMPLEX *c, NUMBER *epsilon);
122 extern COMPLEX *cagd(COMPLEX *c, NUMBER *epsilon);
123
124
125
126 /*
127  * external functions
128  */
129 extern COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
130 extern COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
131 extern COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all);
132
133
134 /*
135  * macro expansions to speed this thing up
136  */
137 #define cisreal(c)      (qiszero((c)->imag))
138 #define cisimag(c)      (qiszero((c)->real) && !cisreal(c))
139 #define ciszero(c)      (cisreal(c) && qiszero((c)->real))
140 #define cisone(c)       (cisreal(c) && qisone((c)->real))
141 #define cisnegone(c)    (cisreal(c) && qisnegone((c)->real))
142 #define cisrunit(c)     (cisreal(c) && qisunit((c)->real))
143 #define cisiunit(c)     (qiszero((c)->real) && qisunit((c)->imag))
144 #define cisunit(c)      (cisrunit(c) || cisiunit(c))
145 #define cistwo(c)       (cisreal(c) && qistwo((c)->real))
146 #define cisint(c)       (qisint((c)->real) && qisint((c)->imag))
147 #define ciseven(c)      (qiseven((c)->real) && qiseven((c)->imag))
148 #define cisodd(c)       (qisodd((c)->real) || qisodd((c)->imag))
149 #define clink(c)        ((c)->links++, (c))
150
151
152 /*
153  * Pre-defined values.
154  */
155 extern COMPLEX _czero_, _cone_, _conei_;
156
157
158 #endif /* !__CMATH_H__ */