<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:37:25 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[GODRIVER-1922] Arithmetic functions with Decimal128</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1922</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;I want to store and use decimals in mongo to represent monetary data.&#160; Looking at the implementation of decimal128 across the other drivers such as python and csharp, it is odd that the maturity of the golang driver implementation lacks the following:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;a. Add, Sub, Mul, Div&lt;/p&gt;

&lt;p&gt;b. IsEqual&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Is there any roadmap for these functions?&lt;/p&gt;</description>
                <environment></environment>
        <key id="1649748">GODRIVER-1922</key>
            <summary>Arithmetic functions with Decimal128</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13203">Gone away</resolution>
                                        <assignee username="benji.rewis@mongodb.com">Benji Rewis</assignee>
                                    <reporter username="sweetat@withevo.com">Swee Tat Lim</reporter>
                        <labels>
                    </labels>
                <created>Tue, 16 Mar 2021 11:58:37 +0000</created>
                <updated>Fri, 27 Oct 2023 20:01:17 +0000</updated>
                            <resolved>Thu, 25 Nov 2021 12:00:11 +0000</resolved>
                                    <version>1.5.0</version>
                                                    <component>BSON</component>
                                        <votes>1</votes>
                                    <watches>10</watches>
                                                                                                                <comments>
                            <comment id="4211659" author="dbeng-pm-bot" created="Thu, 25 Nov 2021 12:00:13 +0000"  >&lt;p&gt;There hasn&apos;t been any recent activity on this ticket, so we&apos;re resolving it. Thanks for reaching out! Please feel free to comment on this if you&apos;re able to provide more information.&lt;/p&gt;</comment>
                            <comment id="4181943" author="benji.rewis" created="Wed, 10 Nov 2021 22:56:46 +0000"  >&lt;p&gt;Hello again &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sweetat%40withevo.com&quot; class=&quot;user-hover&quot; rel=&quot;sweetat@withevo.com&quot;&gt;sweetat@withevo.com&lt;/a&gt;, and thanks again for your feature request.&lt;/p&gt;

&lt;p&gt;Unfortunately, we cannot implement arithmetic functions for the &lt;tt&gt;Decimal128&lt;/tt&gt; type (&lt;tt&gt;Add&lt;/tt&gt;, &lt;tt&gt;Sub&lt;/tt&gt;, &lt;tt&gt;Mul&lt;/tt&gt;, &lt;tt&gt;Div&lt;/tt&gt;). Our specifications for the &lt;tt&gt;Decimal128&lt;/tt&gt; type (to which all drivers must adhere) &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#operator-overloading-and-math-on-decimal128-value-objects&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;explicitly forbid&lt;/a&gt; implementing math operations on the type. No official MongoDB driver, including C# and Python, has arithmetic methods for their BSON &lt;tt&gt;Decimal128&lt;/tt&gt; types. Implementing, maintaining and guaranteeing correctness of IEEE decimal support is far from trivial, and a mistake could be disastrous given the importance of arbitrary-precision-decimal-floating-point-number arithmetic.&lt;/p&gt;

&lt;p&gt;We&#8217;d rather not implement &lt;tt&gt;IsEqual&lt;/tt&gt;, either, as the definition of equality between instances of &lt;tt&gt;primitive.Decimal128&lt;/tt&gt; is not obvious. For example, two {{primitive.Decimal128}}s may have mathematically equivalent values, but differing high and low Int64 encodings (e.g. &#8220;1.2&#8221; and &#8220;1.200&#8221;). Those values&#8217; equality could be ambiguous, and one user&#8217;s definition may not match another&#8217;s.&lt;/p&gt;

&lt;p&gt;As &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=chuntao.lu%40coinbase.com&quot; class=&quot;user-hover&quot; rel=&quot;chuntao.lu@coinbase.com&quot;&gt;chuntao.lu@coinbase.com&lt;/a&gt; mentioned, I understand that converting between &lt;tt&gt;primitive.Decimal128&lt;/tt&gt; and other popular decimal libraries can add undesired overhead to perform arithmetic functions. I gather that the main pain point there is having to check errors for conversions to and from &lt;tt&gt;primitive.Decimal128&lt;/tt&gt;. I can suggest an alternative of registering a custom BSON codec for your preferred decimal type that converts to and from &lt;tt&gt;primitive.Decimal128&lt;/tt&gt;. Doing so would mean that conversion errors only appear in Marshaling and Unmarshaling, and you could insert/query with your preferred decimal type rather than &lt;tt&gt;primitive.Decimal128&lt;/tt&gt;. That way, from your application&#8217;s point of view, you&#8217;d never even touch &lt;tt&gt;primitive.Decimal128&lt;/tt&gt;. Decimal values would only be &lt;em&gt;stored&lt;/em&gt; in your collections as &lt;tt&gt;primitive.Decimal128&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;I&#8217;ve attached an example of registering a custom codec for &lt;a href=&quot;https://github.com/shopspring/decimal&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;shopspring.Decimal&lt;/a&gt;, a popular decimal type with full arithmetic support. I believe this method would make working with decimals more seamless. Let me know what you think.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;nobr&quot;&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/attachment/345160/345160_shopspringcodec.go&quot; title=&quot;shopspringcodec.go attached to GODRIVER-1922&quot;&gt;shopspringcodec.go&lt;sup&gt;&lt;img class=&quot;rendericon&quot; src=&quot;https://jira.mongodb.org/images/icons/link_attachment_7.gif&quot; height=&quot;7&quot; width=&quot;7&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/sup&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="3981561" author="JIRAUSER1261380" created="Wed, 4 Aug 2021 20:18:45 +0000"  >&lt;p&gt;I was redirected to this ticket by our support engineer from Mongo, our use case is exactly about the lack of arithmetic methods on &lt;tt&gt;Decimal128&lt;/tt&gt; type. The decimal type is great, but without the arithmetic support, it is less useful and adds a lot of overhead in our application: we have to convert mongo&apos;s decimal type to a decimal type from another third party lib that supports arithmetics, perform the arithmetic operations and finally convert the result back to mongo&apos;s decimal type for storage.&#160;&lt;/p&gt;

&lt;p&gt;I am surprised that the arithmetic methods are present in other drivers but not in golang driver, would love to see this feature request gets higher priority.&#160;&lt;/p&gt;</comment>
                            <comment id="3683126" author="JIRAUSER1259081" created="Thu, 25 Mar 2021 05:16:21 +0000"  >&lt;p&gt;I&apos;m keen to know which kinds of arithmetic functions will be provided, and if it will achieve feature parity with the other language drivers.&lt;/p&gt;</comment>
                            <comment id="3677689" author="kevin.albertson" created="Mon, 22 Mar 2021 20:35:18 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sweetat%40withevo.com&quot; class=&quot;user-hover&quot; rel=&quot;sweetat@withevo.com&quot;&gt;sweetat@withevo.com&lt;/a&gt;, thank you for the feature request! We do not have immediate plans to implement additional arithmetic methods on Decimal128, but we are opening this for future consideration.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1934252">GODRIVER-2244</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="345160" name="shopspringcodec.go" size="4135" author="benji.rewis@mongodb.com" created="Wed, 10 Nov 2021 22:55:43 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                    <customfield id="customfield_13552" key="com.go2group.jira.plugin.crm:crm_generic_field">
                        <customfieldname>Case</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[[5002K00000xCiUkQAK]]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>GODRIVER-2148</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_21553" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Quarter</customfieldname>
                        <customfieldvalues>
                                        <label>FY22Q4</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hzj3xb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>