[SERVER-32873] Incorrect handling of NumberLong in $pow function Created: 24/Jan/18 Updated: 30/Oct/23 Resolved: 10/Feb/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 3.7.2 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Patrick Meredith | Assignee: | Charlie Swanson |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | bkp, neweng, pull-request | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Fully Compatible | ||||
| Operating System: | ALL | ||||
| Backport Requested: |
v3.6, v3.4, v3.2
|
||||
| Participants: | |||||
| Description |
|
$pow has issues where a NumberLong base of -1 is used with a NumberLong exponent of a negative odd value. For example:
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. |
| Comments |
| Comment by Githook User [ 10/Feb/18 ] |
|
Author: {'email': 'KevinCybura@gmail.com', 'name': 'KevinCybura', 'username': 'KevinCybura'}Message: Signed-off-by: Charlie Swanson <charlie.swanson@mongodb.com> Closes #1211 |
| Comment by Charlie Swanson [ 07/Feb/18 ] |
|
Assigning this to myself since I'm working with Kevin Cybura (a CUNY student, external contributor) to come up with a fix and pull request. |
| Comment by Charlie Swanson [ 31/Jan/18 ] |
|
Looks like this is a straight-up bug in the implementation. Once we determine that the result of the expression can be represented as a long (which is correct in this case), we assume that both numbers are positive. It seems like there should be a special case for when the exponent is negative. When the exponent is negative, the only way we could have the result be a long is when the base is 0, 1, or -1, in which case computing the answer is relatively straightforward. |