<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:01:39 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>[SERVER-2950] floating point representation varies from one way to insert to another ?</title>
                <link>https://jira.mongodb.org/browse/SERVER-2950</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;i&apos;m facing a problem while trying to store geolocalised points and key / values attached to it. The problem i&apos;m encountering is that i need to check if a given point (identified by a couple lat / long) is already existing in the database or not.&lt;br/&gt;
Depending on the way i&apos;m inserting my geolocalised points (either from pymongo, javascript shell or mongoimport), i get different results.&lt;/p&gt;

&lt;p&gt;For instance, i try to store value 0.7 as a float using each of the 3 ways.&lt;/p&gt;

&lt;p&gt;The results i get are the following :&lt;/p&gt;

{ &quot;_id&quot; : ObjectId(&quot;4da6e294aea05d721a4a87b9&quot;), &quot;value_from_mongoimport&quot; : 0.7000000000000001 }
{ &quot;_id&quot; : ObjectId(&quot;4da6e2a3e36333098e18d40c&quot;), &quot;value_from shell&quot; : 0.7 }
{ &quot;_id&quot; : ObjectId(&quot;4da6e2aa11f4ac1bc0000000&quot;), &quot;value_from_pymongo&quot; : 0.7 }

&lt;p&gt;I&apos;m precisely using the &quot;mongoimport way&quot; to store data as it offers better performances than other ways.&lt;/p&gt;

&lt;p&gt;The problem is, at a later time, when i do, from python, somethink like :  &lt;br/&gt;
db.testfind_one(&lt;/p&gt;
{&quot;mykey&quot; : 0.7}
&lt;p&gt;), i get none ......&lt;/p&gt;

&lt;p&gt;I understand the problem of floating point representation, but why is it only affecting mongoimport ? is this something that implies the json to bson transformation ?&lt;/p&gt;

&lt;p&gt;Help appreciated.&lt;/p&gt;

&lt;p&gt;Regards.&lt;/p&gt;
</description>
                <environment>ubuntu 10.10 64 bits</environment>
        <key id="16118">SERVER-2950</key>
            <summary>floating point representation varies from one way to insert to another ?</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</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="9">Done</resolution>
                                        <assignee username="aaron">Aaron Staple</assignee>
                                    <reporter username="lilou63">olivier barbecot</reporter>
                        <labels>
                    </labels>
                <created>Thu, 14 Apr 2011 12:22:42 +0000</created>
                <updated>Tue, 12 Jul 2016 00:19:39 +0000</updated>
                            <resolved>Thu, 9 Jun 2011 16:53:26 +0000</resolved>
                                    <version>1.8.0</version>
                                    <fixVersion>1.9.1</fixVersion>
                                    <component>Tools</component>
                                        <votes>2</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="36885" author="auto" created="Thu, 9 Jun 2011 16:51:57 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;astaple&apos;, u&apos;name&apos;: u&apos;Aaron&apos;, u&apos;email&apos;: u&apos;aaron@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2950&quot; title=&quot;floating point representation varies from one way to insert to another ?&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2950&quot;&gt;&lt;del&gt;SERVER-2950&lt;/del&gt;&lt;/a&gt; use strtod to parse real numbers from json strings&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/19e4da397533e2b7bbd1c217d70a98a72093738f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/19e4da397533e2b7bbd1c217d70a98a72093738f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="35979" author="dsteinberg" created="Fri, 3 Jun 2011 15:57:41 +0000"  >&lt;p&gt;The issue I see here isn&apos;t so much the difference between how python and mongo handle floats, it&apos;s the difference between what the shell does and what mongoimport does.  Mongo ought to be internally consistent, and from there, the Python/Ruby/etc guys can build their drivers appropriately.&lt;/p&gt;

&lt;p&gt;Take this simple document:&lt;/p&gt;

{&quot;_id&quot;:&quot;a&quot;,&quot;lat&quot;:31.437557,&quot;long&quot;:-83.516034}

&lt;p&gt;Calling insert in the shell yields an identical representation.  Stuffing that json string a text file and loading it via mongoimport produces:&lt;/p&gt;

{ &quot;_id&quot; : &quot;a&quot;, &quot;lat&quot; : 31.437556999999998, &quot;long&quot; : -83.516034 }

&lt;p&gt;Clearly there&apos;s a difference in the way those numbers are being handled, and it&apos;s not consistent across the toolset.&lt;/p&gt;</comment>
                            <comment id="30977" author="remonvv" created="Wed, 4 May 2011 16:01:05 +0000"  >&lt;p&gt;Not sure if I agree with that last statement. I agree that equality checks should work if the floating point values are binary equals, and it does. However, mongo has no control over how a specific language/cpu/compiler will convert your &quot;0.7&quot; string to a IEEE 754 floating point value. Many differences are usually the result of rounding strategies (turning 0.10000000149011 back to 0.1 for example). The most obvious problem with this is that something like a 0.7 / 20000.0 == 0.000035 check will actually return false.&lt;/p&gt;

&lt;p&gt;It&apos;s a good software development rule to never to equality checks on floating point numbers. Using small ranges is actually the standard practice when comparing floating point values where the range is usually referred to as epsilon. In other words, your equality check should be (pseudo) : equal = abs(value1 - value2) &amp;lt; epsilon.&lt;/p&gt;

&lt;p&gt;Now, a case can be made to make mongo do this rather than you app but i think that might make floating point equality tests quite a bit slower. That said I&apos;m not sure the binary compare is in any way useful in most apps for the floating point case specifically for stability/accuracy reasons mentioned above.&lt;/p&gt;</comment>
                            <comment id="29643" author="lilou63" created="Tue, 26 Apr 2011 13:13:50 +0000"  >&lt;p&gt;Unfortunately, i am not able to use 1 language exclusively.&lt;/p&gt;

&lt;p&gt;Using floating point queries with small intervals rather than exact matches might be a solution, you&apos;re right, but i&apos;m a bit reluctant with this approach.&lt;/p&gt;

&lt;p&gt;Another solution i found is to use a geohash as the _id.&lt;br/&gt;
This workaround solved my problem.&lt;/p&gt;

&lt;p&gt;I understand different languages parse and print floats differently. Nevertheless languages used in mongodb should all act the same.&lt;/p&gt;

&lt;p&gt;regards. &lt;/p&gt;</comment>
                            <comment id="29333" author="richard@10gen.com" created="Tue, 19 Apr 2011 20:25:54 +0000"  >&lt;p&gt;Different languages parse and print floats differently.  The parser we use in mongoimport seems to differ from the ones used in JavaScript or Python, but none of them is exact, and no two of them agree about both parsing and printing (example below).  &lt;/p&gt;

&lt;p&gt;Are you able to either use one language exclusively, or to code your floating point queries with small intervals rather than exact matches?  &lt;/p&gt;

&lt;p&gt;$ echo &apos;{_id: 1, v: 0.7}&apos; | mongoimport -d server2950 -c test&lt;br/&gt;
connected to: 127.0.0.1&lt;br/&gt;
imported 1 objects&lt;br/&gt;
$ mongo --eval &apos;db.test.save({_id:2, v:0.7})&apos; server2950&lt;br/&gt;
MongoDB shell version: 1.8.0&lt;br/&gt;
connecting to: server2950&lt;br/&gt;
$ python&lt;br/&gt;
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) &lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;GCC 4.2.1 (Apple Inc. build 5646)&amp;#93;&lt;/span&gt; on darwin&lt;br/&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; import pymongo&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; c=pymongo.Collection()&lt;br/&gt;
Traceback (most recent call last):&lt;br/&gt;
  File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;&lt;br/&gt;
AttributeError: &apos;module&apos; object has no attribute &apos;Collection&apos;&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; c=pymongo.Connection()&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db=c&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;server2950&amp;quot;&amp;#93;&lt;/span&gt;&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; db.test.save(&lt;/p&gt;
{&quot;_id&quot;:3, &quot;v&quot;:0.7}
&lt;p&gt;)&lt;br/&gt;
3&lt;br/&gt;
&amp;gt;&amp;gt;&amp;gt; for doc in db.test.find():&lt;br/&gt;
...   print doc&lt;br/&gt;
... &lt;/p&gt;
{u&apos;_id&apos;: 1, u&apos;v&apos;: 0.70000000000000007}
{u&apos;_id&apos;: 2.0, u&apos;v&apos;: 0.69999999999999996}
{u&apos;_id&apos;: 3, u&apos;v&apos;: 0.69999999999999996}
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; exit()&lt;br/&gt;
$ mongo --eval &apos;db.test.find()&apos; server2950&lt;br/&gt;
MongoDB shell version: 1.8.0&lt;br/&gt;
connecting to: server2950&lt;br/&gt;
DBQuery: server2950.test -&amp;gt; undefined&lt;br/&gt;
$ mongo --eval &apos;db.test.find().forEach(printjson)&apos; server2950&lt;br/&gt;
MongoDB shell version: 1.8.0&lt;br/&gt;
connecting to: server2950&lt;/p&gt;
{ &quot;_id&quot; : 1, &quot;v&quot; : 0.7000000000000001 }
{ &quot;_id&quot; : 2, &quot;v&quot; : 0.7 }
{ &quot;_id&quot; : 3, &quot;v&quot; : 0.7 }
&lt;p&gt;$ mongoexport --db server2950 --collection test&lt;br/&gt;
connected to: 127.0.0.1&lt;/p&gt;
{ &quot;_id&quot; : 1, &quot;v&quot; : 0.7000000000000001 }
{ &quot;_id&quot; : 2, &quot;v&quot; : 0.7 }
{ &quot;_id&quot; : 3, &quot;v&quot; : 0.7 }
&lt;p&gt;exported 3 records&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 19 Apr 2011 20:25:54 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 36 weeks, 6 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></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_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            12 years, 36 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>aaron</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>dsteinberg</customfieldvalue>
            <customfieldvalue>lilou63</customfieldvalue>
            <customfieldvalue>remonvv</customfieldvalue>
            <customfieldvalue>richard.kreuter</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp1bj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hriew7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21065</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrnv4n:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>