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

fix(ticks): tickMethods for tiny numbers #163

Merged
merged 1 commit into from
Jul 6, 2021
Merged

fix(ticks): tickMethods for tiny numbers #163

merged 1 commit into from
Jul 6, 2021

Conversation

pearmini
Copy link
Member

修复了下面出现死循环的问题:

extended(9.899999999999999, 9.9)
pretty(9.899999999999999, 9.9)

出现原因是精度问题:

const start = 9.899999999999999;
const end = 9.9;
const step = 5e-15;
for(let i = start; i < end; i += step) {} // 死循环 i += step 始终等于 9.899999999999999
const start = 19799999999999996;
const end = 19799999999999996;
const step = 1;
for(let i = start; i <= end; i += step) {} // 死循环 i += step 始终等于 19799999999999996

解决办法

const start = 9.899999999999999;
const end = 9.9;
const step = 5e-15;
const count = Math.floor((start - end) / step);
for(let i = 0; i < count; i += 1) {}

@hustcc hustcc merged commit 0565231 into master Jul 6, 2021
@hustcc hustcc deleted the fix/ticks-v4 branch July 6, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants