Пример #1
0
Complex add (Complex& a, Complex& b)
{
  double real = a.getReal() + b.getReal();
  double imag = a.getImag() + b.getImag();
  Complex sum (real, imag);
  return sum;
}
Пример #2
0
void Console::draw( ofVec2f pos, int state, int seed, Complex complexStateZero, Complex complexStateOne )
{
    // Draw console to the screen
    ofPushMatrix();
    ofTranslate(pos.x, pos.y);
    
    mFont.drawString("***************************************",0,0);
    for(int i = 1; i < 23; i++)
    {
        mFont.drawString("*", 0,   LINE_SPACING * i);
        mFont.drawString("*", 267, LINE_SPACING * i);
    }
    
    mFont.drawString("Summary", 55, 2 * LINE_SPACING);
    mFont.drawString("=============================", 55, 3 * LINE_SPACING);
    
    mFont.drawString("Measured:      " + ofToString(state), 55,LINE_SPACING*4);
    mFont.drawString("QuantumSeed:   " + ofToString(seed),  55,LINE_SPACING*5);
    
    mFont.drawString("Zero State:    " + ofToString(abs(complexStateZero.getReal())) + " + " + ofToString(complexStateZero.getImag()) + "i",  55,LINE_SPACING*6);
    
    mFont.drawString("One  State:    " + ofToString(abs(complexStateOne.getReal())) + " + " + ofToString(complexStateOne.getImag()) + "i",  55,LINE_SPACING*7);
    
    mFont.drawString("***************************************", 0,LINE_SPACING*23);
    
    mFont.drawString("console log", 55, 9 * LINE_SPACING);
    mFont.drawString("=============================", 55, 10 * LINE_SPACING);
    
    int lineNum = 0;
    for (std::list<string>::const_iterator iterator = mLog.begin(); iterator != mLog.end(); ++iterator) {
        string line = *iterator;
        
        mFont.drawString(" > " + line, 55, (11+lineNum) * LINE_SPACING);
        lineNum++;
    }
    
    ofPopMatrix();
    
    addMessage("Measured state: " + ofToString(state));
    
    // If the quantum seed has changed then write this to the console
    if(seed != mLastQuantumSeed)
    {
        mLastQuantumSeed = seed;
        addMessage("Updated seed: " + ofToString(seed));
    }
}
Пример #3
0
    Php::Value sub(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *a = (Complex *) t.implementation();

        r -= (double) a->getReal();
        i -= (double) a->getImage();

        return this;
    }
Пример #4
0
    Php::Value mul(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *a = (Complex *) t.implementation();

        double tr = r * (double) (a->getReal()) - i * (double) (a->getImage());
        double ti = i * (double) (a->getReal()) + r * (double) (a->getImage());

        r = tr;
        i = ti;
        return this;
    }
Пример #5
0
    Php::Value div(Php::Parameters &params) {
        Php::Value t = params[0];
        Complex *b = (Complex*) t.implementation();

        double t1 = b->mod() * b->mod();

        if (t1 < EPS)
            throw Php::Exception("Division by zero");

        double tr = r * (double) (b->getReal()) + i * (double) (b->getImage());
        double ti = i * (double) (b->getReal()) - r * (double) (b->getImage());

        r = tr / t1;
        i = ti / t1;

        return this;
    }
Пример #6
0
const Complex operator/( const Complex& lComplex, const Complex& rComplex )
// Non-member non-friend operator function
//
// PRE:  (none)
//
// POST: the quotient of this Complex and rComplex is returned
{
    double divisor = rComplex.getReal()*rComplex.getReal()
                   + rComplex.getImag()*rComplex.getImag();

    double realNum = lComplex.getReal()*rComplex.getReal()
                   + lComplex.getImag()*rComplex.getImag();

    double imagNum = lComplex.getImag()*rComplex.getReal() 
                   - lComplex.getReal()*rComplex.getImag();

    return Complex( realNum/divisor, imagNum/divisor );
}
Пример #7
0
bool Complex::operator==(const Complex & right) const
{
	return (getReal() == right.getReal() && getImg() == right.getImg());
}
Пример #8
0
Complex Complex::operator*(const Complex & right) const
{
	return Complex(getReal()*right.getReal()-getImg()*right.getImg(), getReal()*right.getImg()+getImg()*right.getReal());
}
Пример #9
0
Complex::Complex(const Complex &orig) {
        setReal(orig.getReal());
        setImag(orig.getImag());
}
Пример #10
0
Complex Complex::div(const Complex &c) const { 
    Complex cj  = c.complexConjugate();
    Complex nom = mul(cj);
    Complex den = c.mul(cj);
    return nom.mul(Complex(1/den.getReal(), 0));
}
Пример #11
0
Complex operator+(double d, const Complex &c1) {
	return Complex(c1.getReal()+d, c1.getImaginary());
}
Пример #12
0
Complex operator+(const Complex &c1, const Complex &c2) {
	return Complex(c1.getReal()+c2.getReal(), c1.getImaginary()+c2.getImaginary());
}
Пример #13
0
void printComplex(Complex& q){
    cout << "Real part: " << q.getReal() << endl;
    cout << "Imaginary part: " << q.getImaginary() << endl << endl;
}
 Complex operator * (const Complex & rhs) const
 {
     return Complex(m_real * rhs.getReal() - m_imaginary * rhs.getImaginary(), m_imaginary * rhs.getReal() + m_real * rhs.getImaginary());
 }
 Complex operator - (const Complex & rhs) const
 {
     return Complex(m_real - rhs.getReal(), m_imaginary - rhs.getImaginary());
 }
Пример #16
0
Complex operator+(const Complex & c1, double d)
{
	return Complex(c1.getReal() + d, c1.getImagionary());
}