Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.:
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).