[SERVER-50578] Round Decimal128::to{Int,Long,IntExact,LongExact,ULongExact} toward zero Created: 27/Aug/20  Updated: 27/Jan/23

Status: Backlog
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Nikita Lapkov (Inactive) Assignee: Backlog - Storage Execution Team
Resolution: Unresolved Votes: 0
Labels: indexv3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-44618 Quarantine logic which allows generat... Backlog
Assigned Teams:
Storage Execution
Sprint: Execution Team 2020-09-21, Execution Team 2020-10-05, Execution Team 2020-10-19
Participants:

 Description   

BSONElement::numberInt truncates fractional part of double using C-style cast.
For Decimal values this methods uses Decimal128::toInt without any arguments.
This makes Decimal128::toInt to use kRoundTiesToEven rounding strategy (round to nearest integer).
As a result BSONElement::numberInt has different truncation/rounding rules for double and Decimal128 which can be misleading (see SERVER-32960).

Same is valid for BSONElement::numberLong

The best fix is to default these methods to rounding toward zero. Examination of the call sites revealed a similar issue with document value.


Generated at Thu Feb 08 05:23:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.