fix: goto a fractional line lands one wrapping line too high - #1154
Merged
Conversation
int(fractionalPart * 10) truncates, and float64 cannot represent 3.4 exactly, so 3.4 - 3 is 0.3999... and truncates to 3. Round instead, clamped to a single digit.
Windows cannot remove the temp file while the reader still holds it open, which failed the TempDir cleanup in CI.
Owner
|
Thank you. That is indeed better. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In wrap mode,
gthen3.4moves to3.3.Five lines of 800 characters, 80x25 terminal,
ov -w:Cause
goLinetruncates the fractional part:float64 cannot represent
3.4exactly, somath.Modfreturns0.3999...and* 10gives3.99..., which truncates to3. The same happens for3.3,3.8and10.7:Roughly half the single digits are wrong, and the wrong ones are silently off by one rather than failing.
The fix
math.Roundinstead of truncation, clamped to 9 since the fractional part is a single digit.nTh == 0still takes the existing whole-line branch, sog 3is unchanged.Verification
TestRoot_goLineNthinoviewer/action_test.gowalks3.1through3.9and asserts both the status message andtopLX, so it pins the actual scroll position rather than only the label.Reverting just the expression fails it:
go build ./...,go vet ./...,gofmt -landgo test ./...are all clean.Disclosure: written with AI assistance (Claude Code). I reproduced the off-by-one in a real terminal via tmux against binaries built before and after, checked the float behaviour in a standalone program, and ran the mutation check myself.