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

consider expanding to wider data type on math overflow

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.2.0-rc1
    • None
    • Aggregation Framework
    • 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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: