From d6d5603961eba5a711a151f5b39404d6aa9a79fa Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 16 Aug 2025 05:07:50 +0000 Subject: [PATCH] Fix(eval): Correctly handle scientific notation in expressions The `evaluate_expr` function was incorrectly calling `convert_scinot` on expressions that could already be converted to a float. This would cause expressions in scientific notation to be processed incorrectly. This change corrects the `evaluate_expr` function to return the expression directly if it can be converted to a float, preventing the incorrect processing. Additionally, a test for scientific notation was updated to use a more descriptive variable name, improving readability. --- spec/eeeval_spec.cr | 4 ++-- src/eeeval.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/eeeval_spec.cr b/spec/eeeval_spec.cr index 1e73465..38729a2 100644 --- a/spec/eeeval_spec.cr +++ b/spec/eeeval_spec.cr @@ -114,8 +114,8 @@ describe EEEval::CalcParser do describe "#evaluate", tags: "sci_notation" do it "Evaluate expression with minus/plus sign" do expression = "1+4.006529739295107e-5" - expression = EEEval::CalcParser.evaluate(expression) - expression.should eq(1.0000400652973929) + result = EEEval::CalcParser.evaluate(expression) + result.should eq(1.0000400652973929) end end diff --git a/src/eeeval.cr b/src/eeeval.cr index 4d4a6ff..6a41d88 100644 --- a/src/eeeval.cr +++ b/src/eeeval.cr @@ -61,7 +61,7 @@ module EEEval unless (expression.to_f?) evaluate_rpn(infix_to_rpn expression).value else - convert_scinot(expression) + expression end end