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
Don’t format -0 with a sign. #14
Comments
Note that just removing the check @jasondavies added ( |
Hi @mbostock, thanks for prompt response. We are using 3.4.11, and not using format explicitly at all. (but we found that example online that i linked in tweet, and it turns out its not just in our scenario. We are doing it like this:
if we remove Also, we really like the functionality that Is there any way that we could quick fix/override this behavior?? |
If you’re not using a number formatter (such d3.format or scale.tickFormat, or d3.svg.axis), you’re going to have precision issues regardless (e.g., a tick displaying as 0.30000000000000004 because in IEEE 754, that’s the result from 0.1 + 0.2). Tick values cannot be guaranteed to be nice round values because JavaScript does not support arbitrary precision arithmetic. Yes, scale.nice affects the domain and the observed behavior, but it can either introduce or eliminate precision issues. The behavior depends on the exact domain in question and the number of ticks you’re requesting. As with scale.ticks, the scale.nice method cannot guarantee that the domain will have perfectly rounded values because of the limited precision of IEEE 754. If you’re displaying numbers to humans, you should use a number format such as d3.format. If you’re testing whether a number is zero, you should test within epsilon, e.g., |
If the input value is exactly -0, or if when rounded according to the format’s precision is equivalent to -0, we should treat it as exactly 0 rather than -0.
This is necessary because tick values can be slightly off due to floating point precision, so a value that is intended to be exactly 0 may instead be something like -1.7763568394002506e-16. I can’t seem to reproduce this in 4.0’s d3-scale, but it’s definitely the case in 3.x:
Returns:
Related d3/d3@4946a8c.
The text was updated successfully, but these errors were encountered: