See DOCS-7792 - $mod will truncate a double (e.g. 2.7 -> 2), but will round decimals, ties to even (e.g. 3.5 -> 4).
We should be consistent here, probably truncating decimals as well as doubles.
Also, $mod treats it's divisor and remainder arguments as int values. This could lead to unexpected behaviour when these arguments are larger than int. For example:
> db.createCollection('test')
> db.test.insert([
])
> db.test.find({a: {$mod: [4000000000, 0]}})
The last query should return the single record from the test collection, but returns nothing instead.
The suggestion is to truncate decimals and doubles consistently towards zero into long long type.
- is depended on by
-
DRIVERS-874 $mod has inconsistent rounding/truncation behavior
- Closed
- is duplicated by
-
SERVER-50579 $mod truncates divisor and remainder to int value
- Closed
- related to
-
SERVER-32961 Add $fmod, or some way to mod by fractional numbers, to the match expression language
- Backlog