docs: static int wrap(int value, int max)
      {
          int result = value % max;
          if (result < 0) 
          {
              return result + (max > 0 ? max : - max);        
          }
          return result;
      }