Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6166

consider expanding to wider data type on math overflow

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.0-rc1
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None

      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.

            Assignee:
            matt.dannenberg Matt Dannenberg
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: