Jspice3
cmath2.c File Reference
#include "spice.h"
#include "ftedefs.h"
#include "ftecmath.h"
Include dependency graph for cmath2.c:

Go to the source code of this file.

Macros

#define xx1   sin(u) * cosh(v)
 
#define xx2   cos(u) * sinh(v)
 
#define xx3   cos(u) * cosh(v)
 
#define xx4   sin(u) * sinh(v)
 

Functions

char * cx_tan (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_atan (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_norm (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_uminus (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_mean (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_length (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_vector (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_unitvec (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_plus (char *data1, char *data2, short datatype1, short datatype2, length)
 
char * cx_minus (char *data1, char *data2, short datatype1, short datatype2, length)
 
char * cx_times (char *data1, char *data2, short datatype1, short datatype2, length)
 
char * cx_mod (char *data1, char *data2, short datatype1, short datatype2, length)
 
char * cx_rnd (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_gauss (char *data, short type, int length, int *newlength, short *newtype)
 

Macro Definition Documentation

#define xx1   sin(u) * cosh(v)
#define xx2   cos(u) * sinh(v)
#define xx3   cos(u) * cosh(v)
#define xx4   sin(u) * sinh(v)

Function Documentation

char* cx_atan ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 77 of file cmath2.c.

84 {
85  double *d;
86  double *dd = (double *) data;
87  complex *cc = (complex *) data;
88  int i;
89 
90  d = alloc_d(length);
91  *newtype = VF_REAL;
92  *newlength = length;
93  if (type == VF_COMPLEX) {
94  for (i = 0; i < length; i++)
95  d[i] = radtodeg(atan(realpart(&cc[i])));
96  }
97  else {
98  for (i = 0; i < length; i++)
99  d[i] = radtodeg(atan(dd[i]));
100  }
101  return ((char *) d);
102 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define radtodeg(c)
Definition: ftecmath.h:16
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_gauss ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 618 of file cmath2.c.

631 {
632  double *d;
633  complex *c;
634  int i, j, k;
635  double *dd = (double *) data;
636  complex *cc = (complex *) data;
637 
638  d = alloc_d(length);
639  *newtype = VF_REAL;
640  *newlength = length;
641 
642  if (type == VF_COMPLEX) {
643  for (i = 0; i < length; i++) {
644  d[i] = xgauss()*realpart(&cc[i]) + imagpart(&cc[i]);
645  }
646  }
647  else {
648  for (i = 0; i < length; i++) {
649  d[i] = xgauss()*dd[i];
650  }
651  }
652  return ((char *) d);
653 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
double xgauss()
Definition: compose.c:643
Definition: cddefs.h:237
Definition: types.c:18
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_length ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 239 of file cmath2.c.

246 {
247  double *d;
248 
249  *newlength = 1;
250  *newtype = VF_REAL;
251  d = alloc_d(1);
252  *d = length;
253  return ((char *) d);
254 }
#define VF_REAL
Definition: fteconst.h:39
Definition: cddefs.h:237
#define alloc_d(len)
Definition: ftecmath.h:12
char* cx_mean ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 200 of file cmath2.c.

207 {
208  complex *c;
209  double *d;
210  complex *cc = (complex *) data;
211  double *dd = (double *) data;
212  int i;
213 
214  *newlength = 1;
215  rcheck(length > 0, "mean");
216  if (type == VF_REAL) {
217  d = alloc_d(1);
218  *newtype = VF_REAL;
219  for (i = 0; i < length; i++)
220  *d += dd[i];
221  *d /= length;
222  return ((char *) d);
223  }
224  else {
225  c = alloc_c(1);
226  *newtype = VF_COMPLEX;
227  for (i = 0; i < length; i++) {
228  realpart(c) += realpart(cc + i);
229  imagpart(c) += imagpart(cc + i);
230  }
231  realpart(c) /= length;
232  imagpart(c) /= length;
233  return ((char *) c);
234  }
235 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define rcheck(cond, name)
Definition: ftecmath.h:18
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_minus ( char *  data1,
char *  data2,
short  datatype1,
short  datatype2,
length   
)

Definition at line 373 of file cmath2.c.

377 {
378  double *dd1 = (double *) data1;
379  double *dd2 = (double *) data2;
380  double *d;
381  complex *cc1 = (complex *) data1;
382  complex *cc2 = (complex *) data2;
383  complex *c, c1, c2;
384  int i;
385 
386  if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
387  d = alloc_d(length);
388  for (i = 0; i < length; i++)
389  d[i] = dd1[i] - dd2[i];
390  return ((char *) d);
391  }
392  else {
393  c = alloc_c(length);
394  for (i = 0; i < length; i++) {
395  if (datatype1 == VF_REAL) {
396  realpart(&c1) = dd1[i];
397  imagpart(&c1) = 0.0;
398  }
399  else {
400  realpart(&c1) = realpart(&cc1[i]);
401  imagpart(&c1) = imagpart(&cc1[i]);
402  }
403  if (datatype2 == VF_REAL) {
404  realpart(&c2) = dd2[i];
405  imagpart(&c2) = 0.0;
406  }
407  else {
408  realpart(&c2) = realpart(&cc2[i]);
409  imagpart(&c2) = imagpart(&cc2[i]);
410  }
411  realpart(&c[i]) = realpart(&c1) - realpart(&c2);
412  imagpart(&c[i]) = imagpart(&c1) - imagpart(&c2);
413  }
414  return ((char *) c);
415  }
416 }
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_mod ( char *  data1,
char *  data2,
short  datatype1,
short  datatype2,
length   
)

Definition at line 467 of file cmath2.c.

471 {
472  double *dd1 = (double *) data1;
473  double *dd2 = (double *) data2;
474  double *d;
475  complex *cc1 = (complex *) data1;
476  complex *cc2 = (complex *) data2;
477  complex *c, c1, c2;
478  int i, r1, r2, i1, i2, r3, i3;
479 
480  if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
481  d = alloc_d(length);
482  for (i = 0; i < length; i++) {
483  r1 = floor(FTEcabs(dd1[i]));
484  rcheck(r1 > 0, "mod");
485  r2 = floor(FTEcabs(dd2[i]));
486  rcheck(r2 > 0, "mod");
487  r3 = r1 % r2;
488  d[i] = (double) r3;
489  }
490  return ((char *) d);
491  }
492  else {
493  c = alloc_c(length);
494  for (i = 0; i < length; i++) {
495  if (datatype1 == VF_REAL) {
496  realpart(&c1) = dd1[i];
497  imagpart(&c1) = 0.0;
498  } else {
499  realpart(&c1) = realpart(&cc1[i]);
500  imagpart(&c1) = imagpart(&cc1[i]);
501  }
502  if (datatype2 == VF_REAL) {
503  realpart(&c2) = dd2[i];
504  imagpart(&c2) = 0.0;
505  } else {
506  realpart(&c2) = realpart(&cc2[i]);
507  imagpart(&c2) = imagpart(&cc2[i]);
508  }
509  r1 = floor(FTEcabs(realpart(&c1)));
510  rcheck(r1 > 0, "mod");
511  r2 = floor(FTEcabs(realpart(&c2)));
512  rcheck(r2 > 0, "mod");
513  i1 = floor(FTEcabs(imagpart(&c1)));
514  rcheck(i1 > 0, "mod");
515  i2 = floor(FTEcabs(imagpart(&c2)));
516  rcheck(i2 > 0, "mod");
517  r3 = r1 % r2;
518  i3 = i1 % i2;
519  realpart(&c[i]) = (double) r3;
520  imagpart(&c[i]) = (double) i3;
521  }
522  return ((char *) c);
523  }
524 }
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
#define rcheck(cond, name)
Definition: ftecmath.h:18
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define FTEcabs(d)
Definition: ftecmath.h:13
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_norm ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 107 of file cmath2.c.

114 {
115  double *d, largest = 0.0;
116  complex *c;
117  double *dd = (double *) data;
118  complex *cc = (complex *) data;
119  int i;
120 
121  if (type == VF_REAL) {
122  d = alloc_d(length);
123  *newtype = VF_REAL;
124  }
125  else {
126  c = alloc_c(length);
127  *newtype = VF_COMPLEX;
128  }
129  *newlength = length;
130  if (type == VF_COMPLEX) {
131  for (i = 0; i < length; i++)
132  if (cmag(&cc[i]) > largest)
133  largest = cmag(&cc[i]);
134  }
135  else {
136  for (i = 0; i < length; i++)
137  if (FTEcabs(dd[i]) > largest)
138  largest = FTEcabs(dd[i]);
139  }
140  if (largest == 0.0) {
141  fprintf(cp_err, "Error: can't normalize a 0 vector\n");
142  return (NULL);
143  }
144  if (type == VF_COMPLEX) {
145  for (i = 0; i < length; i++) {
146  realpart(&c[i]) = realpart(&cc[i]) / largest;
147  imagpart(&c[i]) = imagpart(&cc[i]) / largest;
148  }
149  return ((char *) c);
150  }
151  else {
152  for (i = 0; i < length; i++)
153  d[i] = dd[i] / largest;
154  return ((char *) d);
155  }
156 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
FILE * cp_err
Definition: help.c:101
Definition: cddefs.h:237
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
static double c
Definition: vectors.c:16
#define cmag(c)
Definition: ftecmath.h:15
#define imagpart(cval)
Definition: cpstd.h:36
#define FTEcabs(d)
Definition: ftecmath.h:13
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_plus ( char *  data1,
char *  data2,
short  datatype1,
short  datatype2,
length   
)

Definition at line 328 of file cmath2.c.

332 {
333  double *dd1 = (double *) data1;
334  double *dd2 = (double *) data2;
335  double *d;
336  complex *cc1 = (complex *) data1;
337  complex *cc2 = (complex *) data2;
338  complex *c, c1, c2;
339  int i;
340 
341  if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
342  d = alloc_d(length);
343  for (i = 0; i < length; i++)
344  d[i] = dd1[i] + dd2[i];
345  return ((char *) d);
346  }
347  else {
348  c = alloc_c(length);
349  for (i = 0; i < length; i++) {
350  if (datatype1 == VF_REAL) {
351  realpart(&c1) = dd1[i];
352  imagpart(&c1) = 0.0;
353  } else {
354  realpart(&c1) = realpart(&cc1[i]);
355  imagpart(&c1) = imagpart(&cc1[i]);
356  }
357  if (datatype2 == VF_REAL) {
358  realpart(&c2) = dd2[i];
359  imagpart(&c2) = 0.0;
360  } else {
361  realpart(&c2) = realpart(&cc2[i]);
362  imagpart(&c2) = imagpart(&cc2[i]);
363  }
364  realpart(&c[i]) = realpart(&c1) + realpart(&c2);
365  imagpart(&c[i]) = imagpart(&c1) + imagpart(&c2);
366  }
367  return ((char *) c);
368  }
369 }
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_rnd ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 573 of file cmath2.c.

585 {
586  double *d;
587  complex *c;
588  int i, j, k;
589  double *dd = (double *) data;
590  complex *cc = (complex *) data;
591 
592  if (type == VF_REAL) {
593  d = alloc_d(length);
594  *newtype = VF_REAL;
595  }
596  else {
597  c = alloc_c(length);
598  *newtype = VF_COMPLEX;
599  }
600  *newlength = length;
601  if (type == VF_COMPLEX) {
602  for (i = 0; i < length; i++) {
603  realpart(&c[i]) = xrandom()*realpart(&cc[i]);
604  imagpart(&c[i]) = xrandom()*imagpart(&cc[i]);
605  }
606  return ((char *) c);
607  }
608  else {
609  for (i = 0; i < length; i++) {
610  d[i] = xrandom()*dd[i];
611  }
612  return ((char *) d);
613  }
614 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
double xrandom()
Definition: compose.c:634
Definition: cddefs.h:237
Definition: types.c:18
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_tan ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 26 of file cmath2.c.

33 {
34  double *d, u, v;
35  complex *c;
36  double *dd = (double *) data;
37  complex *cc = (complex *) data;
38  int i;
39 
40  if (type == VF_REAL) {
41  d = alloc_d(length);
42  *newtype = VF_REAL;
43  }
44  else {
45  c = alloc_c(length);
46  *newtype = VF_COMPLEX;
47  }
48  *newlength = length;
49  if (type == VF_COMPLEX) {
50  for (i = 0; i < length; i++) {
51 rcheck(cos(degtorad(realpart(&cc[i])))*cosh(degtorad(imagpart(&cc[i]))),"tan");
52 rcheck(sin(degtorad(realpart(&cc[i])))*sinh(degtorad(imagpart(&cc[i]))),"tan");
53  u = degtorad(realpart(&cc[i]));
54  v = degtorad(imagpart(&cc[i]));
55  /* The Lattice C compiler won't take multi-line macros, and
56  * CMS won't take >80 column lines....
57  */
58 #define xx1 sin(u) * cosh(v)
59 #define xx2 cos(u) * sinh(v)
60 #define xx3 cos(u) * cosh(v)
61 #define xx4 sin(u) * sinh(v)
62  cdiv(xx1, xx2, xx3, xx4, realpart(&c[i]), imagpart(&c[i]));
63  }
64  return ((char *) c);
65  }
66  else {
67  for (i = 0; i < length; i++) {
68  rcheck(cos(degtorad(dd[i])) != 0, "tan");
69  d[i] = sin(degtorad(dd[i])) / cos(degtorad(dd[i]));
70  }
71  return ((char *) d);
72  }
73 }
#define xx1
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
#define cdiv(r1, i1, r2, i2, r3, i3)
Definition: ftecmath.h:25
#define xx4
Definition: cddefs.h:237
Definition: types.c:18
#define degtorad(c)
Definition: ftecmath.h:17
double cos()
#define rcheck(cond, name)
Definition: ftecmath.h:18
static double c
Definition: vectors.c:16
double sin()
#define imagpart(cval)
Definition: cpstd.h:36
#define xx3
#define xx2
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_times ( char *  data1,
char *  data2,
short  datatype1,
short  datatype2,
length   
)

Definition at line 420 of file cmath2.c.

424 {
425  double *dd1 = (double *) data1;
426  double *dd2 = (double *) data2;
427  double *d;
428  complex *cc1 = (complex *) data1;
429  complex *cc2 = (complex *) data2;
430  complex *c, c1, c2;
431  int i;
432 
433  if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
434  d = alloc_d(length);
435  for (i = 0; i < length; i++)
436  d[i] = dd1[i] * dd2[i];
437  return ((char *) d);
438  }
439  else {
440  c = alloc_c(length);
441  for (i = 0; i < length; i++) {
442  if (datatype1 == VF_REAL) {
443  realpart(&c1) = dd1[i];
444  imagpart(&c1) = 0.0;
445  } else {
446  realpart(&c1) = realpart(&cc1[i]);
447  imagpart(&c1) = imagpart(&cc1[i]);
448  }
449  if (datatype2 == VF_REAL) {
450  realpart(&c2) = dd2[i];
451  imagpart(&c2) = 0.0;
452  } else {
453  realpart(&c2) = realpart(&cc2[i]);
454  imagpart(&c2) = imagpart(&cc2[i]);
455  }
456  realpart(&c[i]) = realpart(&c1) * realpart(&c2)
457  - imagpart(&c1) * imagpart(&c2);
458  imagpart(&c[i]) = imagpart(&c1) * realpart(&c2)
459  + realpart(&c1) * imagpart(&c2);
460  }
461  return ((char *) c);
462  }
463 }
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_uminus ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 160 of file cmath2.c.

167 {
168  double *d;
169  complex *c;
170  double *dd = (double *) data;
171  complex *cc = (complex *) data;
172  int i;
173 
174  if (type == VF_REAL) {
175  d = alloc_d(length);
176  *newtype = VF_REAL;
177  }
178  else {
179  c = alloc_c(length);
180  *newtype = VF_COMPLEX;
181  }
182  *newlength = length;
183  if (type == VF_COMPLEX) {
184  for (i = 0; i < length; i++) {
185  realpart(&c[i]) = - realpart(&cc[i]);
186  imagpart(&c[i]) = - imagpart(&cc[i]);
187  }
188  return ((char *) c);
189  }
190  else {
191  for (i = 0; i < length; i++)
192  d[i] = - dd[i];
193  return ((char *) d);
194  }
195 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
static double c
Definition: vectors.c:16
#define imagpart(cval)
Definition: cpstd.h:36
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_unitvec ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 293 of file cmath2.c.

300 {
301  complex *cc = (complex *) data;
302  double *dd = (double *) data;
303  int i, len;
304  double *d;
305 
306  if (type == VF_REAL)
307  len = FTEcabs(*dd);
308  else
309  len = cmag(cc);
310  if (len == 0)
311  len = 1;
312  d = alloc_d(len);
313  *newlength = len;
314  *newtype = VF_REAL;
315  for (i = 0; i < len; i++)
316  d[i] = 1;
317  return ((char *) d);
318 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define cmag(c)
Definition: ftecmath.h:15
#define FTEcabs(d)
Definition: ftecmath.h:13
#define alloc_d(len)
Definition: ftecmath.h:12
char* cx_vector ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 262 of file cmath2.c.

269 {
270  complex *cc = (complex *) data;
271  double *dd = (double *) data;
272  int i, len;
273  double *d;
274 
275  if (type == VF_REAL)
276  len = FTEcabs(*dd);
277  else
278  len = cmag(cc);
279  if (len == 0)
280  len = 1;
281  d = alloc_d(len);
282  *newlength = len;
283  *newtype = VF_REAL;
284  for (i = 0; i < len; i++)
285  d[i] = i;
286  return ((char *) d);
287 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define cmag(c)
Definition: ftecmath.h:15
#define FTEcabs(d)
Definition: ftecmath.h:13
#define alloc_d(len)
Definition: ftecmath.h:12