From 1305ff92f79f3ae4d84e8a92f5caedda94e076cb Mon Sep 17 00:00:00 2001 From: Hayden Date: Sat, 5 Feb 2022 00:14:49 +1300 Subject: Make parser treat all exponent literals as float --- core/math/expression.cpp | 4 +--- tests/core/math/test_expression.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 0bd8a0abb5..87f8a95970 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -373,6 +373,7 @@ Error Expression::_get_token(Token &r_token) { is_float = true; } else if (c == 'e') { reading = READING_EXP; + is_float = true; } else { reading = READING_DONE; } @@ -409,9 +410,6 @@ Error Expression::_get_token(Token &r_token) { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') { - is_float = true; - } exp_sign = true; } else { diff --git a/tests/core/math/test_expression.h b/tests/core/math/test_expression.h index 5a894b20f3..6e3be541b0 100644 --- a/tests/core/math/test_expression.h +++ b/tests/core/math/test_expression.h @@ -137,7 +137,7 @@ TEST_CASE("[Expression] Scientific notation") { expression.parse("2e5") == OK, "The expression should parse successfully."); CHECK_MESSAGE( - Math::is_equal_approx(double(expression.execute()), 25), + Math::is_equal_approx(double(expression.execute()), 2e5), "The expression should return the expected result."); CHECK_MESSAGE( -- cgit v1.2.3