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
d3.range produces extra array element for fractional strides #2524
Comments
I tried to see what happens in array/range.js if step is 1/18. The k upscale factor will be 1e17.
which is smaller than the upscale stop value of 1e17, and leads to the extra element. Not sure how to go about this issue properly but here are some thoughts:
although this may need to be reversed for negative steps. |
As a workaround without fixing the range function what works in my case is:
I empirically tested this workaround by
which does not find any unexpected range for eps = 1e-16 but does find many for eps = 1e-17; I also tried other domains as in:
which does find problematic fractions (rmax=111 is worse) so above is not perfect (but much better than without the 1-eps adjustment). However, upping the eps to 1e-15 and going through domains:
does not find a problem. |
Ok. I noticed that the API documentation actually mentions that the result is less predictable with fractional step sizes. Now, I know what that means and the behaviour can be considered somewhat documented with this issue. Perhaps there is no good fix ? |
d3/d3-arrays/src/range.js approach works much better. So I think this issue will become resolved in the next version of d3. Therefore the issue is closed. |
Hm, while the new range.js works better, a little bit deeper empirical testing finds the same issue there. See d3/d3-array#5 |
The d3.range function produces an extra element as the last in the array for some fractional strides. For example:
is unexpected while
is expected.
This is perhaps due to floating point precision epsilons not being taken into account, or loss of precision at some type conversion.
The text was updated successfully, but these errors were encountered: