Skip to content

Print non-integer number at full precision in inspect mode #2615

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

Merged
merged 4 commits into from
Aug 20, 2025

Conversation

ntkme
Copy link
Contributor

@ntkme ntkme commented Aug 7, 2025

@ntkme ntkme force-pushed the full-precision-inspect-number branch from d6655d8 to 5669090 Compare August 7, 2025 23:04
@ntkme ntkme marked this pull request as ready for review August 7, 2025 23:15
@ntkme
Copy link
Contributor Author

ntkme commented Aug 7, 2025

I did a GitHub search to find out where people are using or abusing meta.inspect. It turns out most of them are just abuses where it can be replaced with interpolation, list append, etc. In those cases this shouldn't really affect the behavior of the output.

It seems that the "legit" real world usage where this proposed change may have a small impact is: https://github.com/oddbird/true/blob/cfcd111acf0c168fd2f02cfa0c2a939dd199c189/sass/data/_details.scss#L127

@mirisuzanne @jgerigmeyer I think this change would actually make the "unpredictable" slightly better, but it would require change to the logic linked above. If you need to support both sass before and after this change, it can be implemented with a feature detection with meta.inspect(1.00000000001) == meta.inspect(1) to see if it supports high precision output for numbers in inspect mode or not.

@nex3 Any thoughts?

@nex3
Copy link
Contributor

nex3 commented Aug 11, 2025

I'd like to hear what Miriam and Jonny have to say, but in principle I'm supportive of this. meta.inspect() output is generally expected to be more flexible across versions than other API surfaces; we've even got a warning to that effect in the documentation.

@jgerigmeyer
Copy link
Contributor

Yeah, this logic makes sense to me. @mirisuzanne What do you think?

@mirisuzanne
Copy link

mirisuzanne commented Aug 13, 2025

We're not using this for core functionality, and the specific level of precision is incidental to our purpose. But at some point it was common for people to be surprised when e.g. math.div(1,3) was not equal to a copy/pasted output of that equation, something like 0.3333333333. This code was just meant to warn that the Sass output of two values is equal, even though Sass doesn't consider the two values equal internally. So if you're expecting equality here, you might need to round the values.

But maybe string interpolation or some other method is better for comparing what Sass will actually output?

@nex3
Copy link
Contributor

nex3 commented Aug 13, 2025

Yeah, string interpolation or "" + $value will both return the Sass serialization, where meta.inspect() will generally skew towards providing more information than can necessarily be represented by CSS (for example, it will also include complex units).

@nex3 nex3 merged commit 1df71a5 into sass:main Aug 20, 2025
39 checks passed
nex3 pushed a commit to sass/sass-spec that referenced this pull request Aug 20, 2025
@ntkme ntkme deleted the full-precision-inspect-number branch August 20, 2025 23:34
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.

Fuzzy equality requires precision of 11 while dart-sass only has precision of 10
4 participants