Jspice3
ftecmath.h
Go to the documentation of this file.
1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
4 **********/
5 
6 /*
7  * Macros for complex mathematical functions.
8  */
9 
10 /* Some defines used mainly in cmath.c. */
11 #define alloc_c(len) ((complex *) tmalloc((len) * sizeof (complex)))
12 #define alloc_d(len) ((double *) tmalloc((len) * sizeof (double)))
13 #define FTEcabs(d) (((d) < 0.0) ? - (d) : (d))
14 #define cph(c) (atan2(imagpart(c), (realpart(c))))
15 #define cmag(c) (sqrt(imagpart(c) * imagpart(c) + realpart(c) * realpart(c)))
16 #define radtodeg(c) (cx_degrees ? ((c) / 3.14159265358979323846 * 180) : (c))
17 #define degtorad(c) (cx_degrees ? ((c) * 3.14159265358979323846 / 180) : (c))
18 #define rcheck(cond, name) if (!(cond)) { \
19  fprintf(cp_err, "Error: argument out of range for %s\n", name); \
20  return (NULL); }
21 
22 /* Here's a gross one. */
23 #ifndef HAVE_SHORTMACRO
24 
25 #define cdiv(r1, i1, r2, i2, r3, i3) \
26 { \
27  double r, s; \
28  if (FTEcabs(r2) > FTEcabs(i2)) { \
29  r = (i2) / (r2); \
30  s = (r2) + r * (i2); \
31  (r3) = ((r1) + r * (i1)) / s; \
32  (i3) = ((i1) - r * (r1)) / s; \
33  } else { \
34  r = (r2) / (i2); \
35  s = (i2) + r * (r2); \
36  (r3) = (r * (r1) + (i1)) / s; \
37  (i3) = (r * (i1) - (r1)) / s; \
38  } \
39 }
40 
41 #else
42 
43 #define cdiv(r1, i1, r2, i2, r3, i3) cx_cdiv(r1, i1, r2, i2, &r3, &i3)
44 extern void cx_cdiv();
45 
46 #endif
47