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

Explain how $mod handles negative numbers

    XMLWordPrintableJSON

Details

    Description

      The $mod function doesn't describe how it behaves for negative numbers.

      What's -1 % 10, for example? Programming languages are generally split on how to answer this question. Python and Ruby say 9, while Java and C say -1. A nonnegative result is arguably more (mathematically) correct, but MongoDB generally follows Javascript, so maybe it gives -1 here?

      Whichever one MongoDB does today, I can figure out by trial-and-error, but since it's not documented, is it guaranteed to be stable?

      Attachments

        Activity

          People

            Unassigned Unassigned
            xgen-internal-docs Docs Collector User (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              1 year, 14 weeks, 1 day ago