Skip to content

Fix negative coefficients dropped when parsing terms like -2x - #21

Merged
barrybecker4 merged 2 commits into
masterfrom
cursor/fix-negative-coefficient-x-f601
Nov 8, 2026
Merged

barrybecker4 merged 2 commits into
masterfrom
cursor/fix-negative-coefficient-x-f601

Conversation

@barrybecker4

@barrybecker4 barrybecker4 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #9

Summary

  • Negative coefficients in juxtaposed terms keep their digits: -2x, -2.5x, and -.5x no longer collapse to -x (for example -2x at x=3 is -6).
  • Standalone -x and forms that already worked (-2*x, (-2)x) still evaluate correctly.
  • Master already supplies the parser behavior (unary-minus terms as one operand). This PR adds the remaining coverage for decimal negative coefficients and the explicit-star / parenthesized forms.

Test plan

  • Parse serialization: -2x → -2.0 * x; -2.5x / -.5x keep their coefficients
  • Evaluation: -2x at x=3 is -6; -2.5x at x=2 is -5; -.5x at x=3 is -1.5
  • Regression: -2*x and (-2)x still evaluate to -6 at x=3
  • Merged current master; no regression of 2x^2 → 2*(x^2) or unary-minus-as-one-operand behavior
Open in Web Open in Cursor 

cursoragent and others added 2 commits November 8, 2026 14:48
Tokens ending in x that started with '-' were always turned into
Const(-1) * x, discarding digits. Parse the coefficient text instead,
keeping Const(-1) only when the text is exactly "-".

Co-authored-by: Barry G Becker <barrybecker4@yahoo.com>
Master already fixed negative coefficients via unary-minus operand
grouping. Keep this PR's unique coverage for -2.5x, -.5x, -2*x, and
(-2)x without regressing master's 2x^2 or unary-minus behavior.

Co-authored-by: Barry G Becker <barrybecker4@yahoo.com>
@barrybecker4
barrybecker4 merged commit c1f512d into master Nov 8, 2026
1 check passed
@barrybecker4
barrybecker4 deleted the cursor/fix-negative-coefficient-x-f601 branch November 8, 2026 16:06
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.

Negative coefficients are dropped: -2x parses as -x

2 participants