Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-5290

Inline version of TMath::Nint

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed (View Workflow)
    • Medium
    • Resolution: Fixed
    • None
    • None
    • Math Libraries
    • None

    Description

      A benchmark of the digitization algorithm in AliRoot for the ALICE experiment showed a considerable number of function calls to TMath::Nint(...) in inner loops.

      It would be beneficial to have an inlined implementation of this function directly in the TMath.h header. Further, I suggest to provide this as a template function (see below) to avoid code duplication between Float_t and Double_t.
      Another improvement could be the inversion of floating point operation and the test for evenness ( i & 1 && x + 0.5 == T )

      // possible inline implementation of the Nint function
      template<typename T>
      inline Int_t TMath::Nint(T x)
      {
      // Round to nearest integer. Rounds half integers to the nearest
      // even integer.
      int i;
      if (x >= 0)

      { i = int(x + 0.5); if ( i & 1 && x + 0.5 == T(i) ) i--; }

      else

      { i = int(x - 0.5); if ( i & 1 && x - 0.5 == T(i) ) i++; }

      return i;
      }

      Attachments

        Activity

          People

            moneta Lorenzo Moneta
            swenzel Sandro Christian Wenzel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Actual End: