[poincare] Ensure that a float power an integer in a real

Change-Id: I19416271f127ac487f61191cacc6243bb4e0c160
This commit is contained in:
Émilie Feral
2017-04-19 18:48:11 +02:00
parent 3743ae6bce
commit 448e803f78

View File

@@ -47,6 +47,13 @@ Expression * Power::evaluateOnComplex(Complex * c, Complex * d, Context& context
}
/* Third case only c is complex */
float radius = powf(c->r(), d->a());
if (c->b() == 0 && d->a() == roundf(d->a())) {
/* We handle the case -c float and d integer- separatly to avoid getting
* complex result due to float representation: a float power an integer is
* always real. */
return new Complex(Complex::Cartesian(radius, 0.0f));
}
/* Third case only c is complex */
float theta = d->a()*c->th();
return new Complex(Complex::Polar(radius, theta));
}