diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index fda70c6a55..f4f5d854a9 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1869,8 +1869,6 @@ class FormulaResponse(LoncapaResponse): log.debug('formularesponse: error %s in formula' % err) raise StudentInputError("Invalid input: Could not parse '%s' as a formula" % cgi.escape(given)) - if numpy.isnan(student_result) or numpy.isinf(student_result): - return "incorrect" if not compare_with_tolerance(student_result, instructor_result, self.tolerance): return "incorrect" return "correct" diff --git a/common/lib/capa/capa/util.py b/common/lib/capa/capa/util.py index 9f3e8bd3a0..c219a7b5f6 100644 --- a/common/lib/capa/capa/util.py +++ b/common/lib/capa/capa/util.py @@ -1,4 +1,5 @@ from .calc import evaluator, UndefinedVariable +from cmath import isinf #----------------------------------------------------------------------------- # @@ -20,8 +21,11 @@ def compare_with_tolerance(v1, v2, tol): tolerance = tolerance_rel * max(abs(v1), abs(v2)) else: tolerance = evaluator(dict(), dict(), tol) - return abs(v1 - v2) <= tolerance + if isinf(v1) or isinf(v2): + return v1 == v2 # because the other numerical comparison does not work with infinities + else: + return abs(v1 - v2) <= tolerance def contextualize_text(text, context): # private ''' Takes a string with variables. E.g. $a+$b.