1#ifndef PSCF_CPU_COMPLEX_H
2#define PSCF_CPU_COMPLEX_H
11#include <pscf/math/arithmetic.h>
38 double real(fftw_complex
const & a)
49 double imag(fftw_complex
const & a)
62 double abs(fftw_complex
const & a)
63 {
return sqrt(a[0] * a[0] + a[1] * a[1]); }
73 double absSq(fftw_complex
const & a)
74 {
return (a[0] * a[0] + a[1] * a[1]); }
87 void conj(fftw_complex& z, fftw_complex
const & a)
119 void assign(fftw_complex& z,
double const & a,
double const & b)
134 void assign(fftw_complex& z,
double const & a)
149 void assign(fftw_complex& z, fftw_complex
const & a)
164 void assign(fftw_complex & z, std::complex<double>
const& a)
179 void assign(std::complex<double> & z, fftw_complex
const& a)
180 { z = std::complex<double>(a[0], a[1]); }
194 void add(fftw_complex& z, fftw_complex
const& a, fftw_complex
const& b)
210 void add(fftw_complex& z, fftw_complex
const& a,
double const& b)
225 void addEq(fftw_complex& a, fftw_complex
const& b)
240 void addEq(fftw_complex& a,
double const& b)
257 void sub(fftw_complex& z, fftw_complex
const& a, fftw_complex
const& b)
273 void sub(fftw_complex& z, fftw_complex
const& a,
double const& b)
288 void subEq(fftw_complex & a, fftw_complex
const& b)
303 void subEq(fftw_complex & a,
double const& b)
319 double absSqDiff(fftw_complex
const& a, fftw_complex
const& b)
338 void mul(fftw_complex& z, fftw_complex
const& a, fftw_complex
const& b)
340 z[0] = a[0] * b[0] - a[1] * b[1];
341 z[1] = a[1] * b[0] + a[0] * b[1];
354 void mul(fftw_complex& z, fftw_complex
const& a,
double const& b)
369 void mulEq(fftw_complex & a, fftw_complex
const& b)
372 a0 = a[0] * b[0] - a[1] * b[1];
373 a[1] = a[1] * b[0] + a[0] * b[1];
386 void mulEq(fftw_complex & a,
double const& b)
401 void square(fftw_complex& z, fftw_complex
const& a)
403 z[0] = a[0] * a[0] - a[1] * a[1];
404 z[1] = 2.0 * a[1] * a[0];
419 void div(fftw_complex& z, fftw_complex
const& a, fftw_complex
const& b)
421 double bSq = b[0] * b[0] + b[1] * b[1];
422 z[0] = (a[0] * b[0] + a[1] * b[1])/bSq;
423 z[1] = (a[1] * b[0] - a[0] * b[1])/bSq;
436 void div(fftw_complex& z, fftw_complex
const& a,
double const& b)
451 void divEq(fftw_complex & a, fftw_complex
const & b)
453 double bSq = b[0] * b[0] + b[1] * b[1];
454 double a0 = (a[0] * b[0] + a[1] * b[1])/bSq;
455 a[1] = (a[1] * b[0] - a[0] * b[1])/bSq;
468 void divEq(fftw_complex & a,
double const & b)
485 void inverse(fftw_complex& z, fftw_complex
const & a)
487 double aSq = a[0] * a[0] + a[1] * a[1];
503 void assignExp(fftw_complex & z, fftw_complex
const & a)
505 std::complex<double> arg = std::complex<double>(a[0], a[1]);
506 std::complex<double> result = std::exp(arg);
507 z[0] = result.real();
508 z[1] = result.imag();
520 void assignLog(fftw_complex & z, fftw_complex
const & a)
522 std::complex<double> arg = std::complex<double>(a[0], a[1]);
523 std::complex<double> result = std::log(arg);
524 z[0] = result.real();
525 z[1] = result.imag();
549 std::ostream&
operator << (std::ostream& os, fftw_complex
const & z);
void mulEq(fftw_complex &a, fftw_complex const &b)
In-place multiplication of two complex number, a *= b.
double absSq(fftw_complex const &a)
Return square of absolute magnitude of an fftw_complex number.
void addEq(fftw_complex &a, fftw_complex const &b)
In-place addition of fftw_complex numbers, a += b.
void square(fftw_complex &z, fftw_complex const &a)
Complex square of an fftw_complex number, z = a * a.
void div(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Division of fftw_complex numbers, z = a / b .
void inverse(fftw_complex &z, fftw_complex const &a)
Inversion of an fftw_complex number, z = 1 / a .
double imag(fftw_complex const &a)
Return the imaginary part of an fftw_complex number.
void conj(fftw_complex &z, fftw_complex const &a)
Complex conjugate of an fftw_complex, z = a^*.
void assignExp(fftw_complex &z, fftw_complex const &a)
Exponentation of a ffts_complex variable, z = exp(a).
void add(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Addition of fftw_complex numbers, z = a + b.
void sub(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Subtraction of fftw_complex numbers, z = a - b.
double absSqDiff(fftw_complex const &a, fftw_complex const &b)
Return square of the absolute magnitude of a complex difference.
void subEq(fftw_complex &a, fftw_complex const &b)
In-place subtraction of fftw_complex numbers, a -= b.
void assign(fftw_complex &z, double const &a, double const &b)
Create an fftw_complex from real and imaginary parts, z = a + ib.
void mul(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Multiplication of fftw_complex numbers, z = a * b.
double real(fftw_complex const &a)
Return the real part of an fftw_complex number.
void divEq(fftw_complex &a, fftw_complex const &b)
In-place division of fftw_complex numbers, a /= b.
double abs(fftw_complex const &a)
Return absolute magnitude of an fftw_complex number.
void assignLog(fftw_complex &z, fftw_complex const &a)
Logarithm of an fftw_complex variable, z = log(a).
PSCF package top-level namespace.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.