Bson value comparisons incorrect between Double and Int64

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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#.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: