From 08ac542d0d218d58d568407d338867cc81cfebe3 Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Tue, 13 Jul 2021 16:08:48 -0400 Subject: [PATCH] DOCSP-13855-mod-has-inconsistent-rounding --- source/reference/operator/query/mod.txt | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/source/reference/operator/query/mod.txt b/source/reference/operator/query/mod.txt index 85ece0f04c7..bd801e4c903 100644 --- a/source/reference/operator/query/mod.txt +++ b/source/reference/operator/query/mod.txt @@ -117,3 +117,61 @@ operator with an array that contains four elements: "$err" : "bad query: BadValue malformed mod, too many elements", "code" : 16810 } + +Floating Point Arguments +~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``$mod`` expression rounds decimal input towards zero. + +The following examples demonstrate this behavior: + +.. example:: + + Input query: + + .. code-block:: javascript + + db.inventory.find( { qty: { $mod: [ 4.0, 0 ] } } ) + + Results: + + .. code-block:: javascript + :copyable: false + + { _id: 1, item: 'abc123', qty: 0 } + { _id: 3, item: 'ijk123', qty: 12 } + +.. example:: + + Input query: + + .. code-block:: javascript + + db.inventory.find( { qty: { $mod: [ 4.5, 0 ] } } ) + + Results: + + .. code-block:: javascript + :copyable: false + + { _id: 1, item: 'abc123', qty: 0 } + { _id: 3, item: 'ijk123', qty: 12 } + +.. example:: + + Input query: + + .. code-block:: javascript + + db.inventory.find( { qty: { $mod: [ 4.99, 0 ] } } ) + + Results: + + .. code-block:: javascript + :copyable: false + + { _id: 1, item: 'abc123', qty: 0 } + { _id: 3, item: 'ijk123', qty: 12 } + +Each query applies ``4`` to the ``$mod`` expression regardless of +decimal points, resulting in the same result set.