Skip to content

fix: fix division by negative zero returning +Inf instead of -Inf#64

Open
andriibeee wants to merge 2 commits intoVictoriaMetrics:masterfrom
andriibeee:preserve-neg-zero-sign
Open

fix: fix division by negative zero returning +Inf instead of -Inf#64
andriibeee wants to merge 2 commits intoVictoriaMetrics:masterfrom
andriibeee:preserve-neg-zero-sign

Conversation

@andriibeee
Copy link
Copy Markdown

@andriibeee andriibeee commented Apr 4, 2026

fixes VictoriaMetrics/VictoriaMetrics#10296


Summary by cubic

Fixes division by negative zero returning the wrong sign. Constant folding now preserves -0.0 so expressions like 1 / -0.0 yield -Inf.

  • Bug Fixes
    • In simplifyConstantsInBinaryExpr, only rewrite 0 - x to -x when the left is literal +0.0; avoid rewriting -0 - x to keep signed-zero semantics.
    • Added tests for 1 / -0.0, (1) / (-0.0), -1 / 0, -1 / -0.0, (1 - 1) - 0, and (2 - 2) / -1.

Written for commit 4e0c0dc. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="parser.go">

<violation number="1" location="parser.go:197">
P2: Unary-minus preservation logic is overbroad and can rewrite ordinary `0 - x` constant-folded expressions, changing signed-zero semantics.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread parser.go Outdated
@f41gh7 f41gh7 self-assigned this Apr 14, 2026
@f41gh7 f41gh7 self-requested a review April 14, 2026 09:42
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.69%. Comparing base (0dc0e2d) to head (4e0c0dc).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
- Coverage   89.69%   89.69%   -0.01%     
==========================================
  Files          11       11              
  Lines        2969     2988      +19     
==========================================
+ Hits         2663     2680      +17     
- Misses        209      210       +1     
- Partials       97       98       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@makasim makasim requested review from Haleygo and makasim April 20, 2026 12:07
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.

Unexpected sign-loss when dividing by negative zero in MetricsQL

2 participants