Skip to content

Commit c632e1e

Browse files
Merge pull request #190 from lambda-feedback/tr166-printing-floating-point-approximation-of-large-numbers
Changed printing of large numbers when generating simplified response
2 parents b16078c + e2b3554 commit c632e1e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

app/quantity_comparison_evaluation_tests.py

+12
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,17 @@ def test_radians_to_frequency(self):
251251
result = evaluation_function(res, ans, params, include_test_data=True)
252252
assert result["is_correct"] is True
253253

254+
def test_print_floating_point_approximation_of_very_large_numbers(self):
255+
ans = "2.47*10^4 kg/s"
256+
res = "2.47**10^4 kg/s" # This number is large enough than attempting to turn it into a string will cause an error
257+
params = {
258+
'rtol': 0.005,
259+
'comparison': 'expression',
260+
'strict_syntax': False,
261+
'physical_quantity': True,
262+
}
263+
result = evaluation_function(res, ans, params, include_test_data=True)
264+
assert result["is_correct"] is False
265+
254266
if __name__ == "__main__":
255267
pytest.main(['-xk not slow', "--tb=line", os.path.abspath(__file__)])

app/symbolic_comparison_evaluation.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from sympy.parsing.sympy_parser import T as parser_transformations
2-
from sympy import Abs, Equality, latex, pi, Symbol, Add, Pow, Mul, N
2+
from sympy import Abs, Equality, latex, pi, Symbol, Add, Pow, Mul, N, nfloat
33
from sympy.core.function import UndefinedFunction
44
from sympy.printing.latex import LatexPrinter
55
from copy import deepcopy
@@ -776,7 +776,10 @@ def symbolic_comparison(response, answer, params, eval_response) -> dict:
776776
else:
777777
res_print = parse_expression(response, create_sympy_parsing_params(printing_params))
778778
eval_response.latex = LatexPrinter({"symbol_names": printing_symbols, "mul_symbol": r" \cdot "}).doprint(res_print)
779-
eval_response.simplified = str(res)
779+
try:
780+
eval_response.simplified = str(res)
781+
except ValueError:
782+
eval_response.simplified = str(nfloat(res, n=6))
780783

781784
if (not isinstance(res_original, Equality)) and isinstance(ans_original, Equality):
782785
eval_response.is_correct = False

0 commit comments

Comments
 (0)