[SERVER-19627] Add experimental Decimal128 data type support to the MongoDB shell as NumberDecimal Created: 28/Jul/15  Updated: 03/Nov/16  Resolved: 13/Aug/15

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.1.7
Fix Version/s: 3.1.7

Type: Task Priority: Major - P3
Reporter: Raymond Jacobson Assignee: Raymond Jacobson
Resolution: Done Votes: 0
Labels: dnsf
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-19624 Add experimental Decimal128 data type... Closed
is depended on by SERVER-19752 Allow NumberDecimal to be constructed... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Add support for both v8-3.12 and mozjs.

Note: Do not support shell arithmetic operations for NumberDecimal data type. Currently shell arithmetic on NumberLong functions on a float approx., which is not suitable for precise decimal data types.



 Comments   
Comment by Max Hirschhorn [ 03/Nov/16 ]

JavaScript, the language, does not make it possible to implement support for numeric types other than double.

This isn't entirely accurate, as it is possible to inject additional C++ functions to add/subtract/etc. NumberLong and NumberDecimal instances. What isn't possible is to get it to work with the + operator because the valueOf() method will convert to a Number instance. Defining an alternate syntax is what SERVER-14217 and SERVER-19943 are intended to capture.

Comment by Geert Bosch [ 03/Nov/16 ]

Indeed, we cannot. JavaScript, the language, does not make it possible to implement support for numeric types other than double.
So, you might say: "but MongoDB supports addition for NumberLong, right?"

See:

> x=NumberLong("123456789012345678")
NumberLong("123456789012345678")
> y=NumberLong("1")
NumberLong(1)
> x + y
123456789012345680

The arithmetic is performed using double precision floating point, and the result is no longer a NumberLong. This is already confusing and error-prone for NumberLong for people using numbers larger than 2**53. However, for NumberDecimal, we'd get subtly wrong results all the time. This is the reason we don't silently convert NumberDecimal to double precision in the shell.

Comment by Buzz Moschetti [ 03/Nov/16 ]

geert.bosch Do we still not support NumberDecimal math in the shell?

Comment by Githook User [ 13/Aug/15 ]

Author:

{u'username': u'raymondjacobson', u'name': u'Raymond Jacobson', u'email': u'raymond.jacobson@10gen.com'}

Message: SERVER-19627 Add Decimal128 type support to mongo shell
Branch: master
https://github.com/mongodb/mongo/commit/9a81b7f1a6a8e0773703f2007c5a7268eb182b91

Generated at Thu Feb 08 03:51:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.