Description:
New $round function + precision argument for $trunc function
Engineering Ticket Description:
Inclusion of an $int or $round operator, which can reliably group numbers which are semantically the same is thus desired.
Example:
In attempting to perform bucketing in an aggregation pipeline, where the buckets are defined as "each Xth of range Y", these functions are needed.
bucket = int( (x - min) / (max - min) * bucket_count )
|
// This relies on the int() function removing any real part of the number.
|
|
// At a semantic level, the following is the same:
|
bucket = (x - min - mod(x - min, (max - min) * bucket_count) / ((max - min) / bucket_count)
|
Since this is all floating point math it is subject to errors such as 1.000000001 vs 0.999999999, and therefor less accurate.