Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14555

double floating point values are not retrieved exactly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Internal Client
    • None
    • ALL
    • Hide
      {
          mongo::DBClientConnection connection1, connection2, connection3;
          connection1.connect("localhost");
          connection2.connect("localhost");
          connection3.connect("localhost");
      
          for(double v1 = 0;; v1=nextafter(v1,1e32))
          {
            {
              mongo::BSONObj qu = BSON("_id" << 1);
              mongo::BSONObj obj = BSON("_id" << 1 << "value" << v1);
              connection1.update("test.coll", qu, obj, /*upsert*/true, /*multi*/false);
            }
      
            double v2, v3;
            {
              mongo::BSONObj qu = BSON("_id" << 1);
              std::auto_ptr<mongo::DBClientCursor> cursor = connection2.query("test.coll", qu);
              mongo::BSONObj obj = cursor->next();
              v2 = obj["value"].Double();
            }
            {
              mongo::BSONObj qu = BSON("_id" << 1);
              std::auto_ptr<mongo::DBClientCursor> cursor = connection3.query("test.coll", qu);
              mongo::BSONObj obj = cursor->next();
              v3 = obj["value"].Double();
            }
      
            if(v1!=v2)
            {
              std::cout << "v1 = " << v1 << std::endl;
              std::cout << "v2 = " << v2 << std::endl;
            }
            if(v2!=v3)
            {
              std::cout << "v2 = " << v2 << std::endl;
              std::cout << "v3 = " << v3 << std::endl;
            }
          }
          return;
        }
      

      output (exemplary, not deterministic):

      v1 = 4.94066e-323
      v2 = 4.44659e-323
      v1 = 5.43472e-323
      v2 = 4.44659e-323
      v1 = 5.92879e-323
      v2 = 4.44659e-323
      v1 = 6.17582e-322
      v2 = 6.12641e-322
      v2 = 6.12641e-322
      v3 = 6.17582e-322
      v1 = 6.27463e-322
      v2 = 6.22523e-322
      v2 = 6.22523e-322
      v3 = 6.27463e-322
      ...
      
      Show
      { mongo::DBClientConnection connection1, connection2, connection3; connection1.connect( "localhost" ); connection2.connect( "localhost" ); connection3.connect( "localhost" ); for ( double v1 = 0;; v1=nextafter(v1,1e32)) { { mongo::BSONObj qu = BSON( "_id" << 1); mongo::BSONObj obj = BSON( "_id" << 1 << "value" << v1); connection1.update( "test.coll" , qu, obj, /*upsert*/ true , /*multi*/ false ); } double v2, v3; { mongo::BSONObj qu = BSON( "_id" << 1); std ::auto_ptr <mongo::DBClientCursor> cursor = connection2.query( "test.coll" , qu); mongo::BSONObj obj = cursor->next(); v2 = obj[ "value" ].Double(); } { mongo::BSONObj qu = BSON( "_id" << 1); std ::auto_ptr <mongo::DBClientCursor> cursor = connection3.query( "test.coll" , qu); mongo::BSONObj obj = cursor->next(); v3 = obj[ "value" ].Double(); } if(v1!=v2) { std ::cout << "v1 = " << v1 << std ::endl; std ::cout << "v2 = " << v2 << std ::endl; } if(v2!=v3) { std ::cout << "v2 = " << v2 << std ::endl; std ::cout << "v3 = " << v3 << std ::endl; } } return ; } output (exemplary, not deterministic): v1 = 4.94066e-323 v2 = 4.44659e-323 v1 = 5.43472e-323 v2 = 4.44659e-323 v1 = 5.92879e-323 v2 = 4.44659e-323 v1 = 6.17582e-322 v2 = 6.12641e-322 v2 = 6.12641e-322 v3 = 6.17582e-322 v1 = 6.27463e-322 v2 = 6.22523e-322 v2 = 6.22523e-322 v3 = 6.27463e-322 ...

      1. Retrieving a double value from the database may differ from the originally stored value.
      2. Two different connections may retrieve two different values for the same field.

      This is a critical issue for us, because we have to trust that stored and retrieved numbers are exactly equal.

      Versions: we use mongo db 2.6.1 server with 2.4.8 C++ driver (unfortunately we have severe problems to get the 2.6 C++ driver incorporated into our project, but this is different story...)

            Assignee:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Reporter:
            Stefan.Achatz Stefan Achatz
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: