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

Add $round and/or $integer floating-point functions

    • Fully Compatible
    • v4.0

      Inclusion of an $int or $round operator, which can reliably group numbers which are semantically the same is thus desired.

      Example:
      In attempting to perform bucketing in an aggregation pipeline, where the buckets are defined as "each Xth of range Y", these functions are needed.

      bucket = int( (x - min) / (max - min) * bucket_count )
      // This relies on the int() function removing any real part of the number.
      
      // At a semantic level, the following is the same:
      bucket = (x - min - mod(x - min, (max - min) * bucket_count) / ((max - min) / bucket_count) 
      

      Since this is all floating point math it is subject to errors such as 1.000000001 vs 0.999999999, and therefor less accurate.

            Assignee:
            patrick.meredith@mongodb.com Patrick Meredith
            Reporter:
            rod.adams@mongodb.com Rod Adams
            Votes:
            12 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved: