less/less.js — pull request #1814 by seven-phases-max (2014-01-18 06:54:04+00:00)
Title: Rounding of output numbers.

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 options this code may be optimized for better performance.. but this needs 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 (i.e. eventually we would want this improved as well).

Known issues:

(1). Rounding is not apply 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 `.mixin(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 trickery, so I did not just to not break something critical) thus requires more tests/analysis. So there's room for discussion and further improvements.

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