Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-12486

Docs for SERVER-15926: Add $round and/or $integer floating-point functions

      Description

      Description:

      New $round function + precision argument for $trunc function

      Engineering Ticket Description:

      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.

      Scope of changes

      • Update $trunc with new syntax, noting original syntax is still valid
      • Create $round  docs and link appropriately
      • Crosslink between $trunc and $round for users on one page looking for functionality of the other
      • update 4.2 release notes

       

            Assignee:
            ravind.kumar Ravind Kumar (Inactive)
            Reporter:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              5 years, 7 weeks, 2 days ago