本文整理汇总了C++中std::complex类的典型用法代码示例。如果您正苦于以下问题:C++ complex类的具体用法?C++ complex怎么用?C++ complex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了complex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: valid
static bool valid(index_type i, index_type j, matrix_type *output, std::complex<float> const &value)
{
vsip_cscalar_f c = vsip_cmget_f(output, i, j);
return (equal(c.r, value.real()) && equal(c.i, value.imag()));
}
示例2: is_zero
/*!
* \copydoc is_zero
*/
inline bool is_zero(std::complex<double> a) {
return a.real() == 0.0 && a.imag() == 0.0;
}
示例3: set_iq_balance
void set_iq_balance(const std::complex<double> &cor){
_iface->poke32(REG_TX_FE_MAG_CORRECTION, fs_to_bits(cor.real(), 18));
_iface->poke32(REG_TX_FE_PHASE_CORRECTION, fs_to_bits(cor.imag(), 18));
}
示例4: apply
static inline U apply(std::complex<T> const & arg) {
return static_cast<U>(arg.real());
}
示例5: get
arma_inline static T get(const std::complex<T>& val)
{
return -val.real();
}
示例6:
//=================Strassen===============================
QDebug operator <<(QDebug qd,std::complex<double> a)
{
qd<<"("<<QString::number(a.real())/*+","+QString::number(a.imag())*/<<")";
return qd;
}
示例7: readDouble
template <typename T> void readDouble(QDataStream &in, std::complex<T> &el)
{ double v; in >> v; el.real(v); el.imag(0); }
示例8: readComplex
template <typename T> void readComplex(QDataStream &in, std::complex<T> &el)
{ double re, im; in >> re >> im; el.real(re); el.imag(im); }
示例9: abs_sum_value
double abs_sum_value( std::complex< double > const& f ) {
using namespace std ;
return abs(f.real()) + abs(f.imag()) ;
}
示例10: dumpElement
template <typename T> void dumpElement(QDataStream &out, const std::complex<T> &el)
{ out << (double)el.real() << (double)el.imag(); }
示例11: tmp_real
inline static const T tmp_real(const std::complex<T>& X) { return X.real(); }
示例12: mumps_assign_Scalar
inline void mumps_assign_Scalar(ZMUMPS_COMPLEX & a, std::complex<double> b)
{
a.r = b.real();
a.i = b.imag();
}
示例13: atanh
std::complex<T> atanh(const std::complex<T>& z)
{
//
// References:
//
// Eric W. Weisstein. "Inverse Hyperbolic Tangent."
// From MathWorld--A Wolfram Web Resource.
// http://mathworld.wolfram.com/InverseHyperbolicTangent.html
//
// Also: The Wolfram Functions Site,
// http://functions.wolfram.com/ElementaryFunctions/ArcTanh/
//
// Also "Abramowitz and Stegun. Handbook of Mathematical Functions."
// at : http://jove.prohosting.com/~skripty/toc.htm
//
static const T half_pi = static_cast<T>(1.57079632679489661923132169163975144L);
static const T pi = static_cast<T>(3.141592653589793238462643383279502884197L);
static const T one = static_cast<T>(1.0L);
static const T two = static_cast<T>(2.0L);
static const T four = static_cast<T>(4.0L);
static const T zero = static_cast<T>(0);
static const T a_crossover = static_cast<T>(0.3L);
T x = std::fabs(z.real());
T y = std::fabs(z.imag());
T real, imag; // our results
T safe_upper = detail::safe_max(two);
T safe_lower = detail::safe_min(static_cast<T>(2));
//
// Begin by handling the special cases specified in C99:
//
if(detail::test_is_nan(x))
{
if(detail::test_is_nan(y))
return std::complex<T>(x, x);
else if(std::numeric_limits<T>::has_infinity && (y == std::numeric_limits<T>::infinity()))
return std::complex<T>(0, ((z.imag() < 0) ? -half_pi : half_pi));
else
return std::complex<T>(x, x);
}
else if(detail::test_is_nan(y))
{
if(x == 0)
return std::complex<T>(x, y);
if(std::numeric_limits<T>::has_infinity && (x == std::numeric_limits<T>::infinity()))
return std::complex<T>(0, y);
else
return std::complex<T>(y, y);
}
else if((x > safe_lower) && (x < safe_upper) && (y > safe_lower) && (y < safe_upper))
{
T xx = x*x;
T yy = y*y;
T x2 = x * two;
///
// The real part is given by:
//
// real(atanh(z)) == log((1 + x^2 + y^2 + 2x) / (1 + x^2 + y^2 - 2x))
//
// However, when x is either large (x > 1/E) or very small
// (x < E) then this effectively simplifies
// to log(1), leading to wildly inaccurate results.
// By dividing the above (top and bottom) by (1 + x^2 + y^2) we get:
//
// real(atanh(z)) == log((1 + (2x / (1 + x^2 + y^2))) / (1 - (-2x / (1 + x^2 + y^2))))
//
// which is much more sensitive to the value of x, when x is not near 1
// (remember we can compute log(1+x) for small x very accurately).
//
// The cross-over from one method to the other has to be determined
// experimentally, the value used below appears correct to within a
// factor of 2 (and there are larger errors from other parts
// of the input domain anyway).
//
T alpha = two*x / (one + xx + yy);
if(alpha < a_crossover)
{
real = boost::math::log1p(alpha) - boost::math::log1p(-alpha);
}
else
{
T xm1 = x - one;
real = boost::math::log1p(x2 + xx + yy) - std::log(xm1*xm1 + yy);
}
real /= four;
if(z.real() < 0)
real = -real;
imag = std::atan2((y * two), (one - xx - yy));
imag /= two;
if(z.imag() < 0)
imag = -imag;
}
else
//.........这里部分代码省略.........
示例14: ConstantExpr
Expr::Expr(const std::complex<double>& c)
: Playa::Handle<ExprBase>(new ComplexExpr(new ConstantExpr(c.real()),
new ConstantExpr(c.imag())))
{}
示例15: assert
void LTransform::set(
PQIndex pq1, PQIndex pq2, std::complex<double> Cpq1pq2, std::complex<double> Cqp1pq2)
{
assert(pq1.pqValid() && !pq1.pastOrder(_orderOut));
assert(pq2.pqValid() && !pq2.pastOrder(_orderIn));
take_ownership();
const double RoundoffTolerance=1.e-15;
std::complex<double> Cpq1qp2;
if (pq2.needsConjugation()) {
pq2 = pq2.swapPQ();
std::complex<double> tmp=conj(Cqp1pq2);
Cqp1pq2 = conj(Cpq1pq2);
Cpq1pq2 = tmp;
}
if (pq1.needsConjugation()) {
pq1 = pq1.swapPQ();
std::complex<double> tmp=Cqp1pq2;
Cqp1pq2 = Cpq1pq2;
Cpq1pq2 = tmp;
}
int rIndex1 = pq1.rIndex();
int rIndex2 = pq2.rIndex();
int iIndex1 = rIndex1+1;
int iIndex2 = rIndex2+1;
if (pq1.isReal()) {
if (Cpq1pq2!=Cqp1pq2) {
FormatAndThrow<>()
<< "Invalid LTransform elements for p1=q1, " << Cpq1pq2
<< " != " << Cqp1pq2;
}
(*_m)(rIndex1,rIndex2) = Cpq1pq2.real() * (pq2.isReal()? 1. : 2.);
if (pq2.isReal()) {
if (std::abs(Cpq1pq2.imag()) > RoundoffTolerance) {
FormatAndThrow<>()
<< "Nonzero imaginary LTransform elements for p1=q1, p2=q2: "
<< Cpq1pq2;
}
} else {
(*_m)(rIndex1,iIndex2) = -2.*Cpq1pq2.imag();
}
return;
} else if (pq2.isReal()) {
// Here we know p1!=q1:
if (norm(Cpq1pq2-conj(Cqp1pq2))>RoundoffTolerance) {
FormatAndThrow<>()
<< "Inputs to LTransform.set are not conjugate for p2=q2: "
<< Cpq1pq2 << " vs " << Cqp1pq2 ;
}
(*_m)(rIndex1, rIndex2) = Cpq1pq2.real();
(*_m)(iIndex1, rIndex2) = Cpq1pq2.imag();
} else {
// Neither pq is real:
std::complex<double> z=Cpq1pq2 + Cqp1pq2;
(*_m)(rIndex1, rIndex2) = z.real();
(*_m)(rIndex1, iIndex2) = -z.imag();
z=Cpq1pq2 - Cqp1pq2;
(*_m)(iIndex1, rIndex2) = z.imag();
(*_m)(iIndex1, iIndex2) = z.real();
}
}