2 * cmath - data structures for extended precision complex arithmetic
4 * Copyright (C) 1999-2007 David I. Bell
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.
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.
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.1 $
21 * @(#) $Id: cmath.h,v 30.1 2007/03/16 11:09:46 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/cmath.h,v $
24 * Under source code control: 1993/07/30 19:42:45
25 * File existed as early as: 1993
27 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
31 #if !defined(__CMATH_H__)
35 #if defined(CALC_SRC) /* if we are building from the calc source tree */
38 # include <calc/qmath.h>
43 * Complex arithmetic definitions.
46 NUMBER
*real
; /* real part of number */
47 NUMBER
*imag
; /* imaginary part of number */
48 long links
; /* link count */
53 * Input, output, and conversion routines.
55 E_FUNC COMPLEX
*comalloc(void);
56 E_FUNC COMPLEX
*qqtoc(NUMBER
*q1
, NUMBER
*q2
);
57 E_FUNC
void comfree(COMPLEX
*c
);
58 E_FUNC
void comprint(COMPLEX
*c
);
59 E_FUNC
void cprintfr(COMPLEX
*c
);
63 * Basic numeric routines.
66 E_FUNC COMPLEX
*c_add(COMPLEX
*c1
, COMPLEX
*c2
);
67 E_FUNC COMPLEX
*c_sub(COMPLEX
*c1
, COMPLEX
*c2
);
68 E_FUNC COMPLEX
*c_mul(COMPLEX
*c1
, COMPLEX
*c2
);
69 E_FUNC COMPLEX
*c_div(COMPLEX
*c1
, COMPLEX
*c2
);
70 E_FUNC COMPLEX
*c_addq(COMPLEX
*c
, NUMBER
*q
);
71 E_FUNC COMPLEX
*c_subq(COMPLEX
*c
, NUMBER
*q
);
72 E_FUNC COMPLEX
*c_mulq(COMPLEX
*c
, NUMBER
*q
);
73 E_FUNC COMPLEX
*c_divq(COMPLEX
*c
, NUMBER
*q
);
74 E_FUNC COMPLEX
*c_scale(COMPLEX
*c
, long i
);
75 E_FUNC COMPLEX
*c_shift(COMPLEX
*c
, long i
);
76 E_FUNC COMPLEX
*c_square(COMPLEX
*c
);
77 E_FUNC COMPLEX
*c_conj(COMPLEX
*c
);
78 E_FUNC COMPLEX
*c_real(COMPLEX
*c
);
79 E_FUNC COMPLEX
*c_imag(COMPLEX
*c
);
80 E_FUNC COMPLEX
*c_neg(COMPLEX
*c
);
81 E_FUNC COMPLEX
*c_inv(COMPLEX
*c
);
82 E_FUNC COMPLEX
*c_int(COMPLEX
*c
);
83 E_FUNC COMPLEX
*c_frac(COMPLEX
*c
);
84 E_FUNC BOOL
c_cmp(COMPLEX
*c1
, COMPLEX
*c2
);
88 * More complicated functions.
90 E_FUNC COMPLEX
*c_powi(COMPLEX
*c
, NUMBER
*q
);
91 E_FUNC NUMBER
*c_ilog(COMPLEX
*c
, ZVALUE base
);
95 * Transcendental routines. These all take an epsilon argument to
96 * specify how accurately these are to be calculated.
98 E_FUNC COMPLEX
*c_power(COMPLEX
*c1
, COMPLEX
*c2
, NUMBER
*epsilon
);
99 E_FUNC COMPLEX
*c_sqrt(COMPLEX
*c
, NUMBER
*epsilon
, long R
);
100 E_FUNC COMPLEX
*c_root(COMPLEX
*c
, NUMBER
*q
, NUMBER
*epsilon
);
101 E_FUNC COMPLEX
*c_exp(COMPLEX
*c
, NUMBER
*epsilon
);
102 E_FUNC COMPLEX
*c_ln(COMPLEX
*c
, NUMBER
*epsilon
);
103 E_FUNC COMPLEX
*c_log(COMPLEX
*c
, NUMBER
*epsilon
);
104 E_FUNC COMPLEX
*c_cos(COMPLEX
*c
, NUMBER
*epsilon
);
105 E_FUNC COMPLEX
*c_sin(COMPLEX
*c
, NUMBER
*epsilon
);
106 E_FUNC COMPLEX
*c_cosh(COMPLEX
*c
, NUMBER
*epsilon
);
107 E_FUNC COMPLEX
*c_sinh(COMPLEX
*c
, NUMBER
*epsilon
);
108 E_FUNC COMPLEX
*c_polar(NUMBER
*q1
, NUMBER
*q2
, NUMBER
*epsilon
);
109 E_FUNC COMPLEX
*c_rel(COMPLEX
*c1
, COMPLEX
*c2
);
110 E_FUNC COMPLEX
*c_asin(COMPLEX
*c
, NUMBER
*epsilon
);
111 E_FUNC COMPLEX
*c_acos(COMPLEX
*c
, NUMBER
*epsilon
);
112 E_FUNC COMPLEX
*c_atan(COMPLEX
*c
, NUMBER
*epsilon
);
113 E_FUNC COMPLEX
*c_acot(COMPLEX
*c
, NUMBER
*epsilon
);
114 E_FUNC COMPLEX
*c_asec(COMPLEX
*c
, NUMBER
*epsilon
);
115 E_FUNC COMPLEX
*c_acsc(COMPLEX
*c
, NUMBER
*epsilon
);
116 E_FUNC COMPLEX
*c_asinh(COMPLEX
*c
, NUMBER
*epsilon
);
117 E_FUNC COMPLEX
*c_acosh(COMPLEX
*c
, NUMBER
*epsilon
);
118 E_FUNC COMPLEX
*c_atanh(COMPLEX
*c
, NUMBER
*epsilon
);
119 E_FUNC COMPLEX
*c_acoth(COMPLEX
*c
, NUMBER
*epsilon
);
120 E_FUNC COMPLEX
*c_asech(COMPLEX
*c
, NUMBER
*epsilon
);
121 E_FUNC COMPLEX
*c_acsch(COMPLEX
*c
, NUMBER
*epsilon
);
122 E_FUNC COMPLEX
*c_gd(COMPLEX
*c
, NUMBER
*epsilon
);
123 E_FUNC COMPLEX
*c_agd(COMPLEX
*c
, NUMBER
*epsilon
);
130 E_FUNC COMPLEX
*swap_b8_in_COMPLEX(COMPLEX
*dest
, COMPLEX
*src
, BOOL all
);
131 E_FUNC COMPLEX
*swap_b16_in_COMPLEX(COMPLEX
*dest
, COMPLEX
*src
, BOOL all
);
132 E_FUNC COMPLEX
*swap_HALF_in_COMPLEX(COMPLEX
*dest
, COMPLEX
*src
, BOOL all
);
136 * macro expansions to speed this thing up
138 #define cisreal(c) (qiszero((c)->imag))
139 #define cisimag(c) (qiszero((c)->real) && !cisreal(c))
140 #define ciszero(c) (cisreal(c) && qiszero((c)->real))
141 #define cisone(c) (cisreal(c) && qisone((c)->real))
142 #define cisnegone(c) (cisreal(c) && qisnegone((c)->real))
143 #define cisrunit(c) (cisreal(c) && qisunit((c)->real))
144 #define cisiunit(c) (qiszero((c)->real) && qisunit((c)->imag))
145 #define cisunit(c) (cisrunit(c) || cisiunit(c))
146 #define cistwo(c) (cisreal(c) && qistwo((c)->real))
147 #define cisint(c) (qisint((c)->real) && qisint((c)->imag))
148 #define ciseven(c) (qiseven((c)->real) && qiseven((c)->imag))
149 #define cisodd(c) (qisodd((c)->real) || qisodd((c)->imag))
150 #define clink(c) ((c)->links++, (c))
154 * Pre-defined values.
156 EXTERN COMPLEX _czero_
, _cone_
, _conei_
;
159 #endif /* !__CMATH_H__ */