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 precision #416

Merged
merged 1 commit into from
Feb 10, 2024
Merged

Fix precision #416

merged 1 commit into from
Feb 10, 2024

Conversation

facelessuser
Copy link
Collaborator

  • Handle small precision properly
  • Zero precision will return value rounded to integer

Fixes #388

- Handle small precision properly
- Zero precision will return value rounded to integer
Copy link

netlify bot commented Feb 10, 2024

Deploy Preview for colorjs ready!

Name Link
🔨 Latest commit 9370461
🔍 Latest deploy log https://app.netlify.com/sites/colorjs/deploys/65c70807b12f7e00084a01e4
😎 Deploy Preview https://deploy-preview-416--colorjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@facelessuser
Copy link
Collaborator Author

Precision zero will give integer rounding and small values are rounded properly now.

> Color.util.toPrecision(23.3, 0)
23
> Color.util.toPrecision(0.222, 2)
0.22
> Color.util.toPrecision(1e-8, 3)
0
> Color.util.toPrecision(1e-8, 8)
1e-8

@LeaVerou LeaVerou merged commit 2bc2c45 into color-js:main Feb 10, 2024
4 checks passed
@LeaVerou
Copy link
Member

Merged, thanks! But I don't think it fixes #388 entirely, since it was not only about serialization (sure, people can use toPrecision to map the coords, but it seems wrong to require jumping through hoops for common things).

@facelessuser
Copy link
Collaborator Author

Understood, my intention was only to fix the bug. I viewed the other part as an enhancement, one that an official direction was not yet decided upon.

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.

Precision lets scientific notation leak for small values
2 participants