Feat: no more round in quadratic roots

This commit is contained in:
Bertrand Benjamin 2019-07-17 09:55:32 +02:00
parent b93f34bc38
commit aba43c9f19

View File

@ -95,7 +95,7 @@ class Polynomial(Token):
17 17
""" """
return Expression(self._mo.tree)(value) return Expression(self._mo.tree)(value)
def differentiate(self): def differentiate(self):
""" Differentiate a polynome """ Differentiate a polynome
@ -284,17 +284,19 @@ class Quadratic(Polynomial):
if self.delta._mo < 0: if self.delta._mo < 0:
return [] return []
elif self.delta._mo == 0: elif self.delta._mo == 0:
#return [Expression.from_str(f"-{self.b}/(2*{self.a})").simplify()] # return [Expression.from_str(f"-{self.b}/(2*{self.a})").simplify()]
return [round(eval(f"-{self.b}/(2*{self.a})"), 2)] return [round(eval(f"-{self.b}/(2*{self.a})"), 2)]
else: else:
from math import sqrt from math import sqrt
roots = [ roots = [
round(eval(f"(-{self.b}-sqrt({self.delta}))/(2*{self.a})"), 2), str(eval(f"(-{self.b}-sqrt({self.delta}))/(2*{self.a})")),
round(eval(f"(-{self.b}+sqrt({self.delta}))/(2*{self.a})"), 2), str(eval(f"(-{self.b}+sqrt({self.delta}))/(2*{self.a})")),
] ]
roots.sort() roots.sort()
return roots return roots
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4: # vim:set autoindent expandtab tabstop=4 shiftwidth=4: