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

Incorrect handling of NumberLong in $pow function

    • Fully Compatible
    • ALL
    • v3.6, v3.4, v3.2

      $pow has issues where a NumberLong base of -1 is used with a NumberLong exponent of a negative odd value.

      For example:

      Unable to find source-code formatter for language: javascript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      MongoDB Enterprise > db.v.aggregate({$project: {'a': { $pow: [ NumberLong(-1), NumberLong(-5) ]  },  'b' : { $pow: [ -1, NumberLong(-3) ]  }   }  })
      { "_id" : ObjectId("5a689c791de68d211f6234d6"), "a" : NumberLong(1), "b" : -1 }
      

      Removing the NumberLong from either argument causes the right answer. It seems to be related purely to the return type being NumberLong, though I can confirm there are no issues with positive odd exponents.

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: