Definition:
|
atom x2 = round(atom x1, atom inverted_precision=1)
|
Description:
|
round x1 to the specified precision.
|
Comments:
|
The precision is the inverse of what you might have expected, for example:
to round a number to the nearest 0.1, specify an inverted precision of 10,
to round a number to the nearest 1000, specify an inverted precision of 0.001.
This function may be applied to an atom or sq_round() to all elements
of a sequence. The rules for
sequence operations apply.
|
Example:
|
r = round(1.4) -- r is 1
r = round(1.6) -- r is 2
r = round(8.136,100) -- r is 8.14
|
Technicalia
|
The precision is specified in inverted form for a simple practical reason: atoms cannot hold the
exact value of a decimal fraction such as 0.01, which is particularly
significant when attempting to round values near to the accuracy limits of the physical hardware,
where a small deviation in the input can easily manifest as a large discrepancy in the result.
While much the same effect can be observed both when rounding to the nearest very small amount as
when rounding to the nearest very large amount, any discrepancy in the latter is percentagewise
insignificant, and less likely to be multiplied by a very big number, and therefore less critical.
|