-
Notifications
You must be signed in to change notification settings - Fork 267
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
Rounding errors with Color.hsl().string() #127
Comments
Observed when using RGBA |
Which version of |
@Qix- This issue can be observed in node 9.8.0 and with color 3.0.0. This is due to floating point error. There are different ways of dealing with this, possibly using |
@henopied Aware it's a rounding problem. I thought it was fixed in |
Any news on this issue? |
Possibly related. Alpha value don't seem to get rounded
I agree that my input values might be a bit weird but the figma API is returning them unrounded as well. |
This feature would be really great. I don't know why fading a color by
Everything else I've tried has returned a round number as expected. |
@slapbox please read this article before complaining about your particular case of rounding. That's not what the OP is facing, per se. |
@qix it's a rounding error nonetheless. Would you prefer I open a new issue then? |
@slapbox No, because the rounding error you're reporting is only fixable by the IEEE. Feel free to open a bug report regarding the IEEE-754 standard. |
@Qix- I understand calculations are done with floating points, but surely you're not telling me that we can't round |
@slapbox I'm not sure why you're pushing so hard on this. Yes it can be rounded, I just want to make sure you understand where your errors are coming from as opposed to OP's. |
Have their been any decisions made on this issue? Still occurring in 3.1.3 |
It's not just alpha, Color('tomato').hsl().round().string() === "hsl(9.100000000000023, 100%, 63.9%)"
Color('tomato').hsl().round(1).string() === "hsl(9.100000000000023, 100%, 63.9%)"
Color('tomato').hsl().round(5).string() === "hsl(9.100000000000023, 100%, 63.9%)"
Color('tomato').hsl().string() === "hsl(9.100000000000023, 100%, 63.9%)" This happens in 3.1.3. |
The bug is that the library is taking a floating point number, using return new Color(this.color.map(roundToPlace(places)).concat(this.valpha), this.model); and let self = this.model in colorString.to ? this : this.rgb();
self = self.round(typeof places === 'number' ? places : 1);
const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
return colorString.to[self.model](args); The rounding needs to happen at the last minute when the result is passed back to the caller of (Nothing to do with the IEEE.) |
Certain colors (I've only seen this in HSL so far) don't round correctly when calling
string()
.For example:
The text was updated successfully, but these errors were encountered: