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

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

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Sprint:
      Integration 2016-09-19

      Description

      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().

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: