From 448e803f78cfc0b4f2a873e960d5527d0082ea7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 19 Apr 2017 18:48:11 +0200 Subject: [PATCH] [poincare] Ensure that a float power an integer in a real Change-Id: I19416271f127ac487f61191cacc6243bb4e0c160 --- poincare/src/power.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index f94c6796d..c303a50aa 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -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)); }