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

Rounding of output numbers. #1814

Merged
merged 1 commit into from
Jan 21, 2014
Merged

Rounding of output numbers. #1814

merged 1 commit into from
Jan 21, 2014

Conversation

seven-phases-max
Copy link
Member

Fixes #1326, #1810, #1524.

This probably needs some discussion/changes before merging: I hardcoded precision to max. 8 digits after the decimal point but did that via "environment constant" so it can be exposed as a compiler option if necessary (on the other hand if we don't need such option this code may be optimized for better performance.. but that's to be done with some care and more extensive tests since the same code is used in internal calculations for pattern-matching and guard-expressions: see "known issue 2" below).

Known issues:

(1). Rounding is not applied to "hand-written" numbers immediately assigned to properties, e.g:

z {
    @value: 0.999999999;

    1: @value;            // -> 1
    2: 0.999999999 /* */; // -> 1
    // but:
    3: 0.999999999;       // -> 0.999999999
}

There the third value is of tree.Anonymous type which is not rounded. It is possible to round tree.Anonymous too (when it's actually numeric), but I believe it's better to be fixed on another level (not a critical issue anyway since it's hard to imagine why you would need to type 0.999999999 and then want it to be rounded to 1).

(2). Rounding is not applied to values used in "internal" number evaluations like pattern-matching and guard-expressions, e.g.:

z {
    @value: alpha(shade(#000, -15%));
    1: @value;   // -> 1;
    .m1(@value); // RuntimeError: No matching definition was found for `.m1(0.9999999999999999)`
    .m2(@value); // does not match anything for the same reason (@value = 0.9999999999999999)
}

.m1(1) {
    m1-matched: true;
}

.m2(@value) when (@value = 1) {
    m2-matched: true;
}

This is possible to improve/fix using the same code of this PR, but needs some changes in "environment" options passing/handling (and there's some env trickery, so I did not touch it just to not break something critical). So there's room for discussion and further improvements.

Aside from above everything works as expected (see changes in tests).

@matthew-dean
Copy link
Member

Nice work. #2 I agree is a problem, but seems like a step in the right direction.

@lukeapage
Copy link
Member

Looks good.

re: 1, I'd like to actually change that place in the parser that sees if the value is simple enough to make it anonymous to always try and parse

@lukeapage
Copy link
Member

p.s. related issue on clean-css
clean-css/clean-css#163

lukeapage added a commit that referenced this pull request Jan 21, 2014
@lukeapage lukeapage merged commit 8580ff8 into less:master Jan 21, 2014
@seven-phases-max seven-phases-max deleted the numeric-precision branch January 21, 2014 14:45
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.

Percentage rounding error? (yet another issue about them)
3 participants