Skip to content

Conversation

@gunthercox
Copy link
Owner

No description provided.

@gunthercox gunthercox requested a review from Copilot October 11, 2025 22:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the handling of negative numbers in mathematical expressions by improving the parsing logic to correctly distinguish between unary minus (negation) and binary minus (subtraction) operations.

Key changes include:

  • Enhanced tokenization to preserve leading negative signs in numbers
  • Updated expression extraction to handle negative numbers at the beginning of expressions
  • Improved decimal number handling for negative values

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/test_utils.py Added tests for expression extraction with negative numbers and word-based expressions
tests/test_prefix_unary_operations.py Comprehensive test suite for negative number operations, decimals, and unary functions
mathparse/mathparse.py Core logic updates for tokenization, unary operator preprocessing, decimal evaluation, and expression extraction

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


def test_negative_decimal(self):
"""
Test: -3.5 should equal -3.5 (parsed as -3 . 5)
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly describes how -3.5 is parsed. Based on the implementation, -3.5 is tokenized as a single token '-3.5', not as separate tokens '-3', '.', and '5'.

Suggested change
Test: -3.5 should equal -3.5 (parsed as -3 . 5)
Test: -3.5 should equal -3.5 (parsed as a single token '-3.5')

Copilot uses AI. Check for mistakes.
Test: -10.25 + 5 should work correctly
"""
result = mathparse.parse('-10.25 + 5')
# Parses as (-10) . 25 + 5 = -10.25 + 5 = -5.25
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly describes the parsing behavior. The expression '-10.25 + 5' is tokenized as ['-10.25', '+', '5'], not as separate decimal components.

Suggested change
# Parses as (-10) . 25 + 5 = -10.25 + 5 = -5.25
# Parses as ['-10.25', '+', '5'] = -10.25 + 5 = -5.25

Copilot uses AI. Check for mistakes.
'Compute (-3) + 5', language='ENG'
)
# NOTE: Spaces are currently added, but ideally these will be removed
# in the future
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This TODO comment should include a reference to a tracking issue or be more specific about the timeline for this improvement.

Suggested change
# in the future
# in the future (see issue #123 for tracking: https://github.com/yourorg/yourrepo/issues/123)

Copilot uses AI. Check for mistakes.
@gunthercox gunthercox merged commit 623357b into master Oct 11, 2025
5 checks passed
@gunthercox gunthercox deleted the fix branch October 11, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants