-
Notifications
You must be signed in to change notification settings - Fork 18
Fix splitting of negative numbers #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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) |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
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'.
| 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') |
| Test: -10.25 + 5 should work correctly | ||
| """ | ||
| result = mathparse.parse('-10.25 + 5') | ||
| # Parses as (-10) . 25 + 5 = -10.25 + 5 = -5.25 |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
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.
| # Parses as (-10) . 25 + 5 = -10.25 + 5 = -5.25 | |
| # Parses as ['-10.25', '+', '5'] = -10.25 + 5 = -5.25 |
| 'Compute (-3) + 5', language='ENG' | ||
| ) | ||
| # NOTE: Spaces are currently added, but ideally these will be removed | ||
| # in the future |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
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.
| # in the future | |
| # in the future (see issue #123 for tracking: https://github.com/yourorg/yourrepo/issues/123) |
No description provided.