Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1685

Bson value comparisons incorrect between Double and Int64

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • BSON

    Description

      The implementation of BsonValue.compareTo for numeric types does not match the behavior of the server. The problem is that casting the long to double and comparing two doubles will discard precision of very large or very small long values, and therefore result in two values comparing as equal when one is actually larger or smaller. A simple example is:

      > ((double)long.MaxValue) > ((double)(long.MaxValue - 1))
      false
      

      The server algorithm for comparing Int64 and double is here: https://github.com/mongodb/mongo/blob/master/src/mongo/base/compare_numbers.h#L77-L100

      It's easily portable to C#.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: