Пример #1
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;
    }
Пример #2
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;
    }
Пример #3
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;
    }