[SERVER-19676] NumberDecimal(...) + NumberDecimal(...) should not cause string concatentation Created: 13/Jul/15  Updated: 05/Apr/17  Resolved: 13/Feb/17

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: David Hatch Assignee: Mira Carey
Resolution: Done Votes: 1
Labels: decimal-data-type
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-19629 Add round trip & CRUD JavaScript test... Closed
Related
related to SERVER-14217 Support NumberLong arithmetic in mong... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Platforms 2017-01-23, Platforms 2017-02-13
Participants:

 Comments   
Comment by Mira Carey [ 13/Feb/17 ]

Due to the fundamental problems inherent to doing non-floating point math in javascript, there isn't any easy system to hook into to provide arithmetic support for our types. If/when javascript provides operator overloading, or something that looks more live value types, we may revisit the issue. In the meantime, we aren't planning on re-implementing arithmetic via methods.

Comment by Geert Bosch [ 25/Jul/16 ]

JS fundamentally only supports double as numerical type.
Operations with NumberLong exceeding 2**53 will not always work as expected:

> x
NumberLong("1000000000000000000")
> x + 1
NumberLong("1000000000000000000")
> x < (x + 1)
false
> 

Rather providing operators that appear to work on NumberDecimal, but throw away most of the precision and result in inaccurate results, the mongo shell does not support any numerical operations on NumberDecimal. It is possible to compute expressions using NumberDecimal using the MongoDB query and aggregation language though, and these operations are performed accurately using the full precision of the NumberDecimal type.

Comment by Raymond Jacobson [ 12/Aug/15 ]

var x = {}
x + {} in JS gives "[Object object][Object object]"
typeof(x + {}) in JS gives string.

.compare has been implemented on NumberLong in the shell. Operations such as .add, .mul, etc. could be implemented on NumberLong & NumberDecimal as well.

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