[SERVER-24920] Value::integral() incorrectly returns true for Decimal128(2.3) Created: 06/Jul/16  Updated: 19/Nov/16  Resolved: 08/Sep/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.3.14

Type: Bug Priority: Major - P3
Reporter: Charlie Swanson Assignee: Samuel Rossi (Inactive)
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

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



 Comments   
Comment by Githook User [ 08/Sep/16 ]

Author:

{u'name': u'Sam Rossi', u'email': u'sam.rossi@mongodb.com'}

Message: SERVER-24920 fix false positives for `Value::integral` on non-integral decimal values
Branch: master
https://github.com/mongodb/mongo/commit/92aed9bba80474abd4a849226ee6fe2d09ff6abb

Generated at Thu Feb 08 04:07:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.