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

Value::integral() incorrectly returns true for Decimal128(2.3)

    • Fully Compatible
    • ALL
    • Integration 2016-09-19

      Value::integral() is meant to return true only if it is a numeric value, which has no additional decimal places, and can be represented in 32 bits, e.g. 2, 2.0, or Decimal(2.0), but not (1LL << 42), 2.3, or Decimal128(2.3).

      This impacts expressions which require integral arguments, such as $arrayElemAt:

      > db.foo.aggregate([{$project: {a: {$arrayElemAt: [[1,2,3], NumberDecimal(2.3)]}}}])
      { "_id" : ObjectId("57756385ffcefbf178fce217"), "a" : 3 }
      

      I think this can be fixed by simply switching this line to use toIntExact() instead of toInt().

            Assignee:
            sam.rossi@mongodb.com Samuel Rossi (Inactive)
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: