SDDSlib
Loading...
Searching...
No Matches
complex.cc File Reference

Implementation of complex number functions. More...

#include <complex>
#include "mdb.h"

Go to the source code of this file.

Functions

std::complex< double > complexErf (std::complex< double > z, long *flag)
 Computes the complex error function of a given complex number.
 
std::complex< double > cexpi (double p)
 Computes the complex exponential of an imaginary number.
 
std::complex< double > cipowr (std::complex< double > a, int n)
 Raises a complex number to an integer power.
 
void complex_multiply (double *r0, double *i0, double r1, double i1, double r2, double i2)
 Multiplies two complex numbers.
 
void complex_divide (double *r0, double *i0, double r1, double i1, double r2, double i2, double threshold)
 Divides two complex numbers.
 

Detailed Description

Implementation of complex number functions.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, R. Soliday

Definition in file complex.cc.

Function Documentation

◆ cexpi()

std::complex< double > cexpi ( double p)

Computes the complex exponential of an imaginary number.

Parameters
pThe real number representing the imaginary part.
Returns
The complex exponential of the input.

Definition at line 43 of file complex.cc.

43 {
44 std::complex<double> a;
45 a = cos(p) + std::complex<double>(0, 1) * sin(p);
46 return (a);
47}

◆ cipowr()

std::complex< double > cipowr ( std::complex< double > a,
int n )

Raises a complex number to an integer power.

Parameters
aThe base complex number.
nThe exponent (integer).
Returns
The complex number a raised to the power n.

Definition at line 56 of file complex.cc.

56 {
57 int i;
58 std::complex<double> p(1, 0);
59
60 if (n >= 0) {
61 for (i = 0; i < n; i++)
62 p = p * a;
63 return (p);
64 }
65 a = p / a;
66 return (cipowr(a, -n));
67}
std::complex< double > cipowr(std::complex< double > a, int n)
Raises a complex number to an integer power.
Definition complex.cc:56

◆ complex_divide()

void complex_divide ( double * r0,
double * i0,
double r1,
double i1,
double r2,
double i2,
double threshold )

Divides two complex numbers.

Deprecated
These routines are obsolete, really, but some code uses them.
Parameters
r0Pointer to store the real part of the result.
i0Pointer to store the imaginary part of the result.
r1Real part of the numerator complex number.
i1Imaginary part of the numerator complex number.
r2Real part of the denominator complex number.
i2Imaginary part of the denominator complex number.
thresholdThe threshold to prevent division by very small numbers.

Definition at line 105 of file complex.cc.

109 {
110 double tempr, denom;
111
112 if ((denom = sqr(r2) + sqr(i2)) < threshold)
113 denom = threshold;
114 i2 = -i2;
115 tempr = (r1 * r2 - i1 * i2) / denom;
116 *i0 = (r1 * i2 + i1 * r2) / denom;
117 *r0 = tempr;
118}

◆ complex_multiply()

void complex_multiply ( double * r0,
double * i0,
double r1,
double i1,
double r2,
double i2 )

Multiplies two complex numbers.

Deprecated
These routines are obsolete, really, but some code uses them.
Parameters
r0Pointer to store the real part of the result.
i0Pointer to store the imaginary part of the result.
r1Real part of the first complex number.
i1Imaginary part of the first complex number.
r2Real part of the second complex number.
i2Imaginary part of the second complex number.

Definition at line 81 of file complex.cc.

84 {
85 double tempr;
86
87 tempr = r1 * r2 - i1 * i2;
88 *i0 = r1 * i2 + i1 * r2;
89 *r0 = tempr;
90}

◆ complexErf()

std::complex< double > complexErf ( std::complex< double > z,
long * flag )

Computes the complex error function of a given complex number.

Parameters
zThe complex number input.
flagPointer to a flag variable to store computation status.
Returns
The complex error function value of z.

Definition at line 26 of file complex.cc.

26 {
27 double xi, yi;
28 double u = 0, v = 0;
29 long lflag = 0;
30 xi = z.real();
31 yi = z.imag();
32 wofz(&xi, &yi, &u, &v, &lflag);
33 *flag = lflag;
34 return std::complex<double>(u, v);
35}
int wofz(doublereal *xi, doublereal *yi, doublereal *u, doublereal *v, logical *flag__)
Computes the complex error function for a given complex number .
Definition wofz.c:79