BOOST_UBLAS_INLINE ::std::complex<T> round(::std::complex<T> x) { T r = (x.real() > 0.0) ? ::std::floor(x.real() + 0.5) : ::std::ceil(x.real() - 0.5); T i = (x.imag() > 0.0) ? ::std::floor(x.imag() + 0.5) : ::std::ceil(x.imag() - 0.5); return ::std::complex<T>(r,i); }
/*********************************************************************** * Number format overloads **********************************************************************/ static QString toStr(const std::complex<qreal> num, const int) { if (num.real() == 0.0 and num.imag() == 0.0) return "0"; if (num.real() == 0.0) return QString::number(num.imag())+"j"; if (num.imag() == 0.0) return QString::number(num.real()); if (num.imag() < 0.0) return QString("%1%2j").arg(num.real()).arg(num.imag()); return QString("%1+%2j").arg(num.real()).arg(num.imag()); }
TEST_F(FourierIntegralTest, Test) { FourierIntegral fi(2, 0, 1, 100); const std::complex<double> actual = fi.integrate(function); const std::complex<double> expected = (std::exp(std::complex<double>(0, 1)) - std::complex<double>(1,0)) / std::complex<double>(0,1); ASSERT_NEAR(expected.real(), actual.real(), 1E-8) << "real"; ASSERT_NEAR(expected.imag(), actual.imag(), 1E-7) << "imag"; }
inline bool AbsGeq( const std::complex<double> &x, const std::complex<double> &y) { double xsq = x.real() * x.real() + x.imag() * x.imag(); double ysq = y.real() * y.real() + y.imag() * y.imag(); return xsq >= ysq; }
inline bool AbsGeq( const std::complex<float> &x, const std::complex<float> &y) { float xsq = x.real() * x.real() + x.imag() * x.imag(); float ysq = y.real() * y.real() + y.imag() * y.imag(); return xsq >= ysq; }
/***********************************************************************//** * @brief Test a complex value * * @param[in] value Complex value to test. * @param[in] expected Expected complex value. * @param[in] eps Precision of the test. * @param[in] name Test case name. * @param[in] message Test case message. * * Test if the value is comprised in the interval * [expected-eps, expected+eps]. ***************************************************************************/ void GTestSuite::test_value(const std::complex<double>& value, const std::complex<double>& expected, const double& eps, const std::string& name, const std::string& message) { // Set test case name. If no name is specify then build the name from // the actual test parameters. std::string formated_name; if (name != "") { formated_name = format_name(name); } else { formated_name = format_name("Test if "+gammalib::str(value)+ " is comprised within "+ gammalib::str(expected)+" +/- "+ gammalib::str(eps)); } // Create a test case of failure type GTestCase* testcase = new GTestCase(GTestCase::FAIL_TEST, formated_name); // If value is not between in interval [expected-eps, expected+eps] // then signal test as failed and increment the number of failures if ((value.real() > expected.real() + eps) || (value.real() < expected.real() - eps) || (value.imag() > expected.imag() + eps) || (value.imag() < expected.imag() - eps)) { testcase->has_passed(false); m_failures++; } // If no message is specified then build message from test result std::string formated_message; if (message != "") { formated_message = message; } else { formated_message = "Value "+gammalib::str(value)+" not within "+ gammalib::str(expected)+" +/- "+gammalib::str(eps)+ " (value-expected = "+gammalib::str(value-expected)+ ")."; } // Set message testcase->message(formated_message); // Log the result (".","F" or, "E") std::cout << testcase->print(); // Add test case to test suite m_tests.push_back(testcase); // Return return; }
bool operator<=(const std::complex<ValueType> &lhs, const std::complex<ValueType> &rhs) { if (&lhs == &rhs) return true; assert(lhs.imag() == rhs.imag() && lhs.imag() == ValueType(0.0)); return lhs.real() <= rhs.real(); }
double TwoDimensionalPlotPage::getValue(const std::complex<long double> val) { switch(Phase) { case AmplitudePhaseType: return sqrt(val.real()*val.real() + val.imag()*val.imag()); case PhasePhaseType: return atan2(val.imag(), val.real()); case RealPhaseType: return val.real(); case ImaginaryPhaseType: return val.imag(); } }
symbol_t operator()(const std::complex<int16_t> in) { const uint32_t real2 = in.real() * in.real(); const uint32_t imag2 = in.imag() * in.imag(); const uint32_t mag2 = real2 + imag2; const uint32_t mag2_attenuated = mag2 >> 3; // Approximation of (-4.5dB)^2 mag2_threshold = (uint64_t(mag2_threshold) * uint64_t(mag2_threshold_leak_factor)) >> 32; mag2_threshold = std::max(mag2_threshold, mag2_attenuated); const bool symbol = (mag2 > mag2_threshold); return symbol; }
/*********************************************************************** * Convert xx to items32 sc8 buffer **********************************************************************/ template <typename T> UHD_INLINE item32_t xx_to_item32_sc8_x1( const std::complex<T> &in0, const std::complex<T> &in1, const double scale_factor ){ boost::uint8_t real0 = boost::int8_t(in0.real()*float(scale_factor)); boost::uint8_t imag0 = boost::int8_t(in0.imag()*float(scale_factor)); boost::uint8_t real1 = boost::int8_t(in1.real()*float(scale_factor)); boost::uint8_t imag1 = boost::int8_t(in1.imag()*float(scale_factor)); return (item32_t(real0) << 8) | (item32_t(imag0) << 0) | (item32_t(real1) << 24) | (item32_t(imag1) << 16) ; }
arma_hot inline typename T1::elem_type op_cdot::apply_proxy(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type<eT>::result T; typedef typename Proxy<T1>::ea_type ea_type1; typedef typename Proxy<T2>::ea_type ea_type2; const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor) || (Proxy<T2>::prefer_at_accessor); if(prefer_at_accessor == false) { const Proxy<T1> PA(X); const Proxy<T2> PB(Y); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "cdot(): objects must have the same number of elements" ); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); T val_real = T(0); T val_imag = T(0); for(uword i=0; i<N; ++i) { const std::complex<T> AA = A[i]; const std::complex<T> BB = B[i]; const T a = AA.real(); const T b = AA.imag(); const T c = BB.real(); const T d = BB.imag(); val_real += (a*c) + (b*d); val_imag += (a*d) - (b*c); } return std::complex<T>(val_real, val_imag); } else { return op_cdot::apply_unwrap( X, Y ); } }
void Biquad::setZeroPolePairs(std::complex<double> zero, std::complex<double> pole) { double b0 = 1; double b1 = -2 * zero.real(); double zeroMag = abs(zero); double b2 = zeroMag * zeroMag; double a1 = -2 * pole.real(); double poleMag = abs(pole); double a2 = poleMag * poleMag; setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); }
// ###### Configure algorithm ############################################### void FractalAlgorithmInterface::configure(unsigned int width, unsigned int height, std::complex<double> c1, std::complex<double> c2, unsigned int maxIterations) { Width = width; Height = height; MaxIterations = maxIterations; C1 = c1; C2 = c2; StepX = (c2.real() - c1.real()) / Width; StepY = (c2.imag() - c1.imag()) / Height; }
void Analytic_Mt2_2220_Calculator::insertIfOK(const std::complex<double> & c, std::vector<double> & goodSinValues) { bool isOk = false; if (c.imag()==0 || fabs(c.imag())<1.0E-10) { isOk = true; } else if (c.real() != 0 && fabs(c.imag()/c.real())<1.E-6) { isOk = true; } if (isOk) { goodSinValues.push_back(c.real()); } }
// No special checks for safe Convert static std::complex<float> safeConvert( const std::complex<double> t ) { float ret_r = Teuchos::as<float>( t.real() ); float ret_i = Teuchos::as<float>( t.imag() ); std::complex<float> ret (ret_r, ret_i); return (ret); }
T abs2(std::complex<T> val) { T re = val.real(); T im = val.imag(); return (re*re)+(im*im); }
inline clapack::doublecomplex std_to_lapack( const std::complex<clapack::doublereal>& v) { clapack::doublecomplex r; r.r = v.real(); r.i = v.imag(); return r; }
void actionQueryBaselines(const std::string &kindName, const std::string &filename) { MeasurementSet *ms = new MeasurementSet(filename); const unsigned polarizationCount = ms->PolarizationCount(); delete ms; const QualityTablesFormatter::StatisticKind kind = QualityTablesFormatter::NameToKind(kindName); QualityTablesFormatter formatter(filename); StatisticsCollection collection(polarizationCount); collection.Load(formatter); const std::vector<std::pair<unsigned, unsigned> > &baselines = collection.BaselineStatistics().BaselineList(); StatisticsDerivator derivator(collection); std::cout << "ANTENNA1\tANTENNA2"; for(unsigned p=0;p<polarizationCount;++p) std::cout << '\t' << kindName << "_POL" << p << "_R\t" << kindName << "_POL" << p << "_I" ; std::cout << '\n'; for(std::vector<std::pair<unsigned, unsigned> >::const_iterator i=baselines.begin();i!=baselines.end();++i) { const unsigned antenna1 = i->first, antenna2 = i->second; std::cout << antenna1 << '\t' << antenna2; for(unsigned p=0;p<polarizationCount;++p) { const std::complex<long double> val = derivator.GetComplexBaselineStatistic(kind, antenna1, antenna2, p); std::cout << '\t' << val.real() << '\t' << val.imag(); } std::cout << '\n'; } }
inline static std::complex<T> trunc_exp(const std::complex<T>& x) { return std::polar( trunc_exp( x.real() ), x.imag() ); }
void serialize(input_archive& ar, std::complex<T>& c, unsigned) { T real, imag; ar >> real >> imag; c.real(real); c.imag(imag); }
static void put(index_type i, vector_type* input, std::complex<float> value) { vsip_cscalar_f cval; cval.r = value.real(); cval.i = value.imag(); vsip_cvput_f(input, i, cval); }
static void get(index_type i, vector_type* output, std::complex<float>& value) { vsip_cscalar_f cval; cval = vsip_cvget_f(output, i); value.real() = cval.r; value.imag() = cval.i; }
/*********************************************************************** * Convert xx to items32 sc16 buffer **********************************************************************/ template <typename T> UHD_INLINE item32_t xx_to_item32_sc16_x1( const std::complex<T> &num, const double scale_factor ){ boost::uint16_t real = boost::int16_t(num.real()*float(scale_factor)); boost::uint16_t imag = boost::int16_t(num.imag()*float(scale_factor)); return (item32_t(real) << 16) | (item32_t(imag) << 0); }
Schuss::Schuss(Engine* mengine, double angle, std::complex<double> position, double speed, ObjectType type) :Object(mengine, type, position.real(), position.imag(), speed*cos((angle+90)/180*M_PI),speed*sin((angle-90)/180*M_PI)), Type(type), Weight(1), Age(0) { //std::cout << "Schuss::Schuss();" << std::endl; Angle = angle; }
void actionQueryTime(const std::string &kindName, const std::string &filename) { const unsigned polarizationCount = MeasurementSet::PolarizationCount(filename); const QualityTablesFormatter::StatisticKind kind = QualityTablesFormatter::NameToKind(kindName); QualityTablesFormatter formatter(filename); StatisticsCollection collection(polarizationCount); collection.Load(formatter); const std::map<double, DefaultStatistics> &timeStats = collection.TimeStatistics(); StatisticsDerivator derivator(collection); std::cout << "TIME"; for(unsigned p=0;p<polarizationCount;++p) std::cout << '\t' << kindName << "_POL" << p << "_R\t" << kindName << "_POL" << p << "_I" ; std::cout << '\n'; for(std::map<double, DefaultStatistics>::const_iterator i=timeStats.begin();i!=timeStats.end();++i) { const double time = i->first; std::cout << time; for(unsigned p=0;p<polarizationCount;++p) { const std::complex<long double> val = derivator.GetComplexStatistic(kind, i->second, p); std::cout << '\t' << val.real() << '\t' << val.imag(); } std::cout << '\n'; } }
size_t EMData::add_complex_at(int x,int y,int z,const int &subx0,const int &suby0,const int &subz0,const int &fullnx,const int &fullny,const int &fullnz,const std::complex<float> &val) { if (abs(x)>=fullnx/2 || abs(y)>fullny/2 || abs(z)>fullnz/2) return nxyz; //if (x==0 && (y!=0 || z!=0)) add_complex_at(0,-y,-z,subx0,suby0,subz0,fullnx,fullny,fullnz,conj(val)); // complex conjugate insertion. Removed due to ambiguity with returned index /*if (x==0&& (y!=0 || z!=0)) { int yy=y<=0?-y:fullny-y; int zz=z<=0?-z:fullnz-z; if (yy<suby0||zz<subz0||yy>=suby0+ny||zz>=subz0+nz) return nx*ny*nz; size_t idx=(yy-suby0)*nx+(zz-subz0)*nx*ny; rdata[idx]+=(float)val.real(); rdata[idx+1]+=(float)-val.imag(); }*/ float cc=1.0; if (x<0) { x*=-1; y*=-1; z*=-1; cc=-1.0; } if (y<0) y=fullny+y; if (z<0) z=fullnz+z; if (x<subx0||y<suby0||z<subz0||x>=subx0+nx||y>=suby0+ny||z>=subz0+nz) return nxyz; size_t idx=(x-subx0)*2+(y-suby0)*(size_t)nx+(z-subz0)*(size_t)nx*ny; rdata[idx]+=(float)val.real(); rdata[idx+1]+=cc*(float)val.imag(); return idx; }
// randomize complex numbers template <class T, class RNG> void randomize(std::complex<T> &v, RNG &rng) { T real, imag; randomize(real, rng); randomize(imag, rng); v.real(real); v.imag(imag); }
std::complex<double> cerf_continued_fraction(const std::complex<double>& z) { if (z.real() > 0) return 1.0 - cerfc_continued_fraction(z); else return -1.0 + cerfc_continued_fraction(-z); }
int main() { const std::complex<float> cd(2.5, 3.5); std::complex<long double> cf = cd; assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); }
// Reconstruction d'un contour à partir de ses descripteurs de Fourier std::vector<std::vector<cv::Point>> reconstruction ( std::vector<std::complex<double>> coeff, int N, int c_max, std::complex<double> z_moy, double scale) { int c_min = -c_max; std::vector<std::complex<double>> TC (N, 0); int debut = coeff.size() + c_min - 1; for (unsigned int i = debut; i < coeff.size(); ++i) { TC[i - debut] = (double) N * coeff[i]; } for (int i = 0; i < c_max; ++i) { TC[N + c_min + i] = (double) N * coeff[i]; } std::vector<std::complex<double>> z_fil; cv::dft(TC, z_fil, cv::DFT_INVERSE + cv::DFT_SCALE); z_fil.push_back(z_fil[0]); std::vector<cv::Point> z_fill; for (auto& i : z_fil) { cv::Point pt(scale * i.real() + z_moy.real(), scale * i.imag() + z_moy.imag()); z_fill.push_back(pt); } std::vector<std::vector<cv::Point>> contour; contour.push_back(z_fill); return contour; }