Skip to content
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

Correct numerical errors in roundedFrameSection calculation #1355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wtmoose
Copy link

@wtmoose wtmoose commented Jun 27, 2022

In my project, I have a calendar view that scrolls horizontaly one month at a time:

image

When calling calendar.scrollToDate(), the calendar was scrolling to the wrong month anytime the specified date was a Sunday. Specifically, it was scrolling to the next previous month.

The problem is due to the formula floor(frameSection) in targetPointForItemAt(). Naturally, frameSection may have small numerical errors. For example, a Sunday may yield frameSection == 49.9999999999999. However, floor(49.9999999999999) == 49 when the correct calculation should be 50.

One potential fix, which is the one I'm submitting in this PR, is to reduce the numerical precision of frameSection from double to single before calling floor(). This correctly results in floor(50) == 50.

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.

None yet

1 participant