From f7817a79aed7fd472ab2ed1584be4a2faa645a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 14 Jun 2017 12:20:31 +0200 Subject: [PATCH] [poincare] Handle real fractions apart from complex fractions Change-Id: I0caa905c8ddc4a85db31a0dc5e5bc4ffd49c31c4 --- poincare/src/fraction.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/poincare/src/fraction.cpp b/poincare/src/fraction.cpp index 3f1f569b6..ed2bb0912 100644 --- a/poincare/src/fraction.cpp +++ b/poincare/src/fraction.cpp @@ -34,6 +34,13 @@ Expression::Type Fraction::type() const { Expression * Fraction::evaluateOnComplex(Complex * c, Complex * d, Context& context, AngleUnit angleUnit) const { float norm = d->a()*d->a() + d->b()*d->b(); + /* We handle the case of c and d pure real numbers apart. Even if the complex + * fraction is mathematically correct on real numbers, it requires more + * operations and is thus more likely to propagate errors due to float exact + * representation. */ + if (d->b() == 0.0f && c->b() == 0.0f) { + return new Complex(Complex::Float(c->a()/d->a())); + } return new Complex(Complex::Cartesian((c->a()*d->a()+c->b()*d->b())/norm, (d->a()*c->b()-c->a()*d->b())/norm)); }