feat: floating-point / epsilon output comparison #258
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
barrettruth/cp.nvim#258
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
normalize_linesinlua/cp/runner/run.luaperforms exact string comparison after whitespace normalization. Many problems — particularly geometry, optimization, and probability problems on AtCoder and Codeforces — specify "absolute or relative error ≤ 1e-6" acceptance criteria. This means a correct solution that outputs0.666667fails against expected0.6666666667. cp.nvim currently reports these as WA incorrectly.Proposed solution
Add a
comparisonconfig option per-platform or globally:When
mode = "epsilon", tokenize both actual and expected outputs, and for each pair of tokens: if both parse as floats, compare with|a - b| <= epsilon * max(1, |b|)(relative+absolute); otherwise compare as exact strings.Additionally, auto-detect from the scraped problem metadata (or the Competitive Companion
testTypefield) when epsilon comparison is appropriate and offer to set it.Alternatives considered
Requiring the user to always configure this manually. But since we scrape constraints, we should be able to detect "the answer must have an absolute error of at most 1e-9" from the problem statement and set the mode automatically.
NOTE: could we intelligently derive this from the problem statement? or at least try to?
NOTE: investigate all other ways we could get wa - anything else