Php::Value sub(Php::Parameters ¶ms) { Php::Value t = params[0]; Complex *a = (Complex *) t.implementation(); r -= (double) a->getReal(); i -= (double) a->getImage(); return this; }
Php::Value mul(Php::Parameters ¶ms) { 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; }
Php::Value div(Php::Parameters ¶ms) { 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; }