Details
-
Question
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Observed behavior: The result of multiplying two 32 bit integers is a 32 bit integer, even if there is an overflow.
Proposed behavior: Rather than overflow, an alternative numeric type will be used to store the result when possible.
c = db.c;
|
c.drop();
|
|
|
c.save( {} );
|
assert.eq( NumberLong( '4611686018427390000' ),
|
// Current behavior on overflow is for the multiplication result to be zero.
|
c.aggregate( { $project:{ a:{ $multiply:[ NumberInt( '2147483648' ), NumberInt( '2147483648' )\
|
] } } } ).result[ 0 ].a );
|
Consider addition and subtraction overflow as well. For numeric addition and subtraction, adding two 32 bit ints will produce a 32 bit int. Currently division is implemented to always return a double.
Also consider for accumulators like $sum.
Attachments
Issue Links
- is duplicated by
-
SERVER-6510 $sum can cause int overflow
-
- Closed
-
- is related to
-
SERVER-5239 $project should have numeric type coercion operators
-
- Closed
-
- related to
-
SERVER-6203 Aggregation operators should have well defined implicit type coercion behavior.
-
- Backlog
-
-
SERVER-6197 $avg is calculated using integer math for integers even though result value is of type double
-
- Closed
-