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

Go to the source code of this file.

Functions

char * cx_mag (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_ph (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_j (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_real (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_imag (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_pos (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_db (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_log (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_ln (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_exp (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_sqrt (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_sin (char *data, short type, int length, int *newlength, short *newtype)
 
char * cx_cos (char *data, short type, int length, int *newlength, short *newtype)
 

Variables

bool cx_degrees = false
 

Function Documentation

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

Definition at line 522 of file cmath1.c.

529 {
530  double *d;
531  complex *c;
532  double *dd = (double *) data;
533  complex *cc = (complex *) data;
534  int i;
535 
536  if (type == VF_REAL) {
537  d = alloc_d(length);
538  *newtype = VF_REAL;
539  }
540  else {
541  c = alloc_c(length);
542  *newtype = VF_COMPLEX;
543  }
544  *newlength = length;
545  if (type == VF_COMPLEX) {
546  for (i = 0; i < length; i++) {
547  realpart(&c[i]) = cos(degtorad(realpart(&cc[i]))) *
548  cosh(degtorad(imagpart(&cc[i])));
549  imagpart(&c[i]) = - sin(degtorad(realpart(&cc[i]))) *
550  sinh(degtorad(imagpart(&cc[i])));
551  }
552  return ((char *) c);
553  }
554  else {
555  for (i = 0; i < length; i++)
556  d[i] = cos(degtorad(dd[i]));
557  return ((char *) d);
558  }
559 }
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 degtorad(c)
Definition: ftecmath.h:17
double cos()
static double c
Definition: vectors.c:16
double sin()
#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_db ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 193 of file cmath1.c.

200 {
201  double *d = alloc_d(length);
202  double *dd = (double *) data;
203  complex *cc = (complex *) data;
204  double tt;
205  int i;
206 
207  *newlength = length;
208  *newtype = VF_REAL;
209  if (type == VF_COMPLEX)
210  for (i = 0; i < length; i++) {
211  tt = cmag(&cc[i]);
212  rcheck(tt >= 0, "db");
213  if (tt == 0.0)
214  d[i] = 20.0 * - log(HUGE);
215  else
216  d[i] = 20.0 * log10(tt);
217  }
218  else
219  for (i = 0; i < length; i++) {
220  rcheck(dd[i] >= 0, "db");
221  if (dd[i] == 0.0)
222  d[i] = 20.0 * - log(HUGE);
223  else
224  d[i] = 20.0 * log10(dd[i]);
225  }
226  return ((char *) d);
227 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: xforms.c:16
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define rcheck(cond, name)
Definition: ftecmath.h:18
#define cmag(c)
Definition: ftecmath.h:15
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define HUGE
Definition: spice.h:128
char* cx_exp ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 340 of file cmath1.c.

347 {
348  double *d, td;
349  complex *c;
350  double *dd = (double *) data;
351  complex *cc = (complex *) data;
352  int i;
353 
354  if (type == VF_REAL) {
355  d = alloc_d(length);
356  *newtype = VF_REAL;
357  }
358  else {
359  c = alloc_c(length);
360  *newtype = VF_COMPLEX;
361  }
362  *newlength = length;
363  if (type == VF_COMPLEX) {
364  for (i = 0; i < length; i++) {
365  td = exp(realpart(&cc[i]));
366  realpart(&c[i]) = td * cos(realpart(&cc[i]));
367  imagpart(&c[i]) = td * sin(imagpart(&cc[i]));
368  }
369  return ((char *) c);
370  }
371  else {
372  for (i = 0; i < length; i++)
373  d[i] = exp(dd[i]);
374  return ((char *) d);
375  }
376 }
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
double cos()
static double c
Definition: vectors.c:16
double sin()
#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_imag ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 140 of file cmath1.c.

147 {
148  double *d = alloc_d(length);
149  double *dd = (double *) data;
150  complex *cc = (complex *) data;
151  int i;
152 
153  *newlength = length;
154  *newtype = VF_REAL;
155  if (type == VF_COMPLEX)
156  for (i = 0; i < length; i++)
157  d[i] = imagpart(&cc[i]);
158  else
159  for (i = 0; i < length; i++)
160  d[i] = dd[i];
161  return ((char *) d);
162 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define imagpart(cval)
Definition: cpstd.h:36
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
char* cx_j ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 84 of file cmath1.c.

91 {
92  complex *c = alloc_c(length);
93  complex *cc = (complex *) data;
94  double *dd = (double *) data;
95  int i;
96 
97  *newlength = length;
98  *newtype = VF_COMPLEX;
99  if (type == VF_COMPLEX)
100  for (i = 0; i < length; i++) {
101  realpart(&c[i]) = - imagpart(&cc[i]);
102  imagpart(&c[i]) = realpart(&cc[i]);
103  }
104  else
105  for (i = 0; i < length; i++) {
106  imagpart(&c[i]) = dd[i];
107  /* Real part is already 0. */
108  }
109  return ((char *) c);
110 }
Definition: subckt.c:18
#define alloc_c(len)
Definition: ftecmath.h:11
Definition: cpstd.h:29
Definition: types.c:18
#define imagpart(cval)
Definition: cpstd.h:36
Definition: cddefs.h:177
#define VF_COMPLEX
Definition: fteconst.h:40
#define realpart(cval)
Definition: cpstd.h:35
char* cx_ln ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 287 of file cmath1.c.

294 {
295  double *d, td;
296  complex *c;
297  double *dd = (double *) data;
298  complex *cc = (complex *) data;
299  int i;
300 
301  if (type == VF_REAL) {
302  d = alloc_d(length);
303  *newtype = VF_REAL;
304  }
305  else {
306  c = alloc_c(length);
307  *newtype = VF_COMPLEX;
308  }
309  *newlength = length;
310  if (type == VF_COMPLEX) {
311  for (i = 0; i < length; i++) {
312  td = cmag(&cc[i]);
313  rcheck(td >= 0, "ln");
314  if (td == 0.0) {
315  realpart(&c[i]) = - log(HUGE);
316  imagpart(&c[i]) = 0.0;
317  }
318  else {
319  realpart(&c[i]) = log(td);
320  imagpart(&c[i]) = atan2(imagpart(&cc[i]),
321  realpart(&cc[i]));
322  }
323  }
324  return ((char *) c);
325  }
326  else {
327  for (i = 0; i < length; i++) {
328  rcheck(dd[i] >= 0, "ln");
329  if (dd[i] == 0.0)
330  d[i] = - log(HUGE);
331  else
332  d[i] = log(dd[i]);
333  }
334  return ((char *) d);
335  }
336 }
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 cmag(c)
Definition: ftecmath.h:15
#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
#define HUGE
Definition: spice.h:128
char* cx_log ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 231 of file cmath1.c.

238 {
239  double *d, td;
240  complex *c;
241  double *dd = (double *) data;
242  complex *cc = (complex *) data;
243  int i;
244 
245  if (type == VF_REAL) {
246  d = alloc_d(length);
247  *newtype = VF_REAL;
248  }
249  else {
250  c = alloc_c(length);
251  *newtype = VF_COMPLEX;
252  }
253  *newlength = length;
254  if (type == VF_COMPLEX) {
255  for (i = 0; i < length; i++) {
256  td = cmag(&cc[i]);
257  /* Perhaps we should trap when td = 0.0, but Ken wants
258  * this to be possible...
259  */
260  rcheck(td >= 0, "log");
261  if (td == 0.0) {
262  realpart(&c[i]) = - log10(HUGE);
263  imagpart(&c[i]) = 0.0;
264  }
265  else {
266  realpart(&c[i]) = log10(td);
267  imagpart(&c[i]) = atan2(imagpart(&cc[i]),
268  realpart(&cc[i]));
269  }
270  }
271  return ((char *) c);
272  }
273  else {
274  for (i = 0; i < length; i++) {
275  rcheck(dd[i] >= 0, "log");
276  if (dd[i] == 0.0)
277  d[i] = - log10(HUGE);
278  else
279  d[i] = log10(dd[i]);
280  }
281  return ((char *) d);
282  }
283 }
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 cmag(c)
Definition: ftecmath.h:15
#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
#define HUGE
Definition: spice.h:128
char* cx_mag ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 33 of file cmath1.c.

40 {
41  double *d = alloc_d(length);
42  double *dd = (double *) data;
43  complex *cc = (complex *) data;
44  int i;
45 
46  *newlength = length;
47  *newtype = VF_REAL;
48  if (type == VF_REAL)
49  for (i = 0; i < length; i++)
50  d[i] = FTEcabs(dd[i]);
51  else
52  for (i = 0; i < length; i++)
53  d[i] = cmag(&cc[i]);
54  return ((char *) d);
55 }
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_ph ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 59 of file cmath1.c.

66 {
67  double *d = alloc_d(length);
68  complex *cc = (complex *) data;
69  int i;
70 
71  *newlength = length;
72  *newtype = VF_REAL;
73  if (type == VF_COMPLEX)
74  for (i = 0; i < length; i++) {
75  d[i] = radtodeg(cph(&cc[i]));
76  }
77  /* Otherwise it is 0, but tmalloc zeros the stuff already. */
78  return ((char *) d);
79 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
#define cph(c)
Definition: ftecmath.h:14
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
char* cx_pos ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 167 of file cmath1.c.

174 {
175  double *d = alloc_d(length);
176  double *dd = (double *) data;
177  complex *cc = (complex *) data;
178  int i;
179 
180  *newlength = length;
181  *newtype = VF_REAL;
182  if (type == VF_COMPLEX)
183  for (i = 0; i < length; i++)
184  d[i] = ((realpart(&cc[i]) > 0.0) ? 1.0 : 0.0);
185  else
186  for (i = 0; i < length; i++)
187  d[i] = ((dd[i] > 0.0) ? 1.0 : 0.0);
188  return ((char *) d);
189 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_real ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 114 of file cmath1.c.

121 {
122  double *d = alloc_d(length);
123  double *dd = (double *) data;
124  complex *cc = (complex *) data;
125  int i;
126 
127  *newlength = length;
128  *newtype = VF_REAL;
129  if (type == VF_COMPLEX)
130  for (i = 0; i < length; i++)
131  d[i] = realpart(&cc[i]);
132  else
133  for (i = 0; i < length; i++)
134  d[i] = dd[i];
135  return ((char *) d);
136 }
Definition: subckt.c:18
#define VF_REAL
Definition: fteconst.h:39
Definition: cpstd.h:29
Definition: cddefs.h:237
Definition: types.c:18
#define VF_COMPLEX
Definition: fteconst.h:40
#define alloc_d(len)
Definition: ftecmath.h:12
#define realpart(cval)
Definition: cpstd.h:35
char* cx_sin ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 481 of file cmath1.c.

488 {
489  double *d;
490  complex *c;
491  double *dd = (double *) data;
492  complex *cc = (complex *) data;
493  int i;
494 
495  if (type == VF_REAL) {
496  d = alloc_d(length);
497  *newtype = VF_REAL;
498  }
499  else {
500  c = alloc_c(length);
501  *newtype = VF_COMPLEX;
502  }
503  *newlength = length;
504  if (type == VF_COMPLEX) {
505  for (i = 0; i < length; i++) {
506  realpart(&c[i]) = sin(degtorad(realpart(&cc[i]))) *
507  cosh(degtorad(imagpart(&cc[i])));
508  imagpart(&c[i]) = cos(degtorad(realpart(&cc[i]))) *
509  sinh(degtorad(imagpart(&cc[i])));
510  }
511  return ((char *) c);
512  }
513  else {
514  for (i = 0; i < length; i++)
515  d[i] = sin(degtorad(dd[i]));
516  return ((char *) d);
517  }
518 }
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 degtorad(c)
Definition: ftecmath.h:17
double cos()
static double c
Definition: vectors.c:16
double sin()
#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_sqrt ( char *  data,
short  type,
int  length,
int *  newlength,
short *  newtype 
)

Definition at line 380 of file cmath1.c.

387 {
388  double *d;
389  complex *c;
390  double *dd = (double *) data;
391  complex *cc = (complex *) data;
392  int i, cres = (type == VF_REAL) ? 0 : 1;
393 
394  if (type == VF_REAL)
395  for (i = 0; i < length; i++)
396  if (dd[i] < 0.0)
397  cres = 1;
398  if (cres) {
399  c = alloc_c(length);
400  *newtype = VF_COMPLEX;
401  }
402  else {
403  d = alloc_d(length);
404  *newtype = VF_REAL;
405  }
406  *newlength = length;
407  if (type == VF_COMPLEX) {
408  for (i = 0; i < length; i++) {
409  if (realpart(&cc[i]) == 0.0) {
410  if (imagpart(&cc[i]) == 0.0) {
411  realpart(&c[i]) = 0.0;
412  imagpart(&c[i]) = 0.0;
413  }
414  else if (imagpart(&cc[i]) > 0.0) {
415  realpart(&c[i]) = sqrt (0.5 *
416  imagpart(&cc[i]));
417  imagpart(&c[i]) = realpart(&c[i]);
418  }
419  else {
420  imagpart(&c[i]) = sqrt( -0.5 *
421  imagpart(&cc[i]));
422  realpart(&c[i]) = - imagpart(&c[i]);
423  }
424  }
425  else if (realpart(&cc[i]) > 0.0) {
426  if (imagpart(&cc[i]) == 0.0) {
427  realpart(&c[i]) =
428  sqrt(realpart(&cc[i]));
429  imagpart(&c[i]) = 0.0;
430  }
431  else if (imagpart(&cc[i]) < 0.0) {
432  realpart(&c[i]) = -sqrt(0.5 *
433  (cmag(&cc[i]) + realpart(&cc[i])));
434  }
435  else {
436  realpart(&c[i]) = sqrt(0.5 *
437  (cmag(&cc[i]) + realpart(&cc[i])));
438  }
439  imagpart(&c[i]) = imagpart(&cc[i]) / (2.0 *
440  realpart(&c[i]));
441  }
442  else { /* realpart(&cc[i]) < 0.0) */
443  if (imagpart(&cc[i]) == 0.0) {
444  realpart(&c[i]) = 0.0;
445  imagpart(&c[i]) =
446  sqrt(- realpart(&cc[i]));
447  }
448  else {
449  if (imagpart(&cc[i]) < 0.0)
450  imagpart(&c[i]) = - sqrt(0.5 *
451  (cmag(&cc[i]) -
452  realpart(&cc[i])));
453  else
454  imagpart(&c[i]) = sqrt(0.5 *
455  (cmag(&cc[i]) -
456  realpart(&cc[i])));
457  realpart(&c[i]) = imagpart(&cc[i]) /
458  (2.0 * imagpart(&c[i]));
459  }
460  }
461  }
462  return ((char *) c);
463  }
464  else if (cres) {
465  for (i = 0; i < length; i++)
466  if (dd[i] < 0.0)
467  imagpart(&c[i]) = sqrt(- dd[i]);
468  else
469  realpart(&c[i]) = sqrt(dd[i]);
470  return ((char *) c);
471  }
472  else {
473  for (i = 0; i < length; i++)
474  d[i] = sqrt(dd[i]);
475  return ((char *) d);
476  }
477 }
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 cmag(c)
Definition: ftecmath.h:15
#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

Variable Documentation

bool cx_degrees = false

Definition at line 30 of file cmath1.c.