
unsigned short ushort_min(unsigned short left, unsigned short right)
{
  if (left > right) return right;
  return left;
}

unsigned short ushort_max(unsigned short left, unsigned short right)
{
  if (left > right) return left;
  return right;
}

unsigned short decrease(unsigned short original, unsigned short interval, unsigned short bound)
{
  if ( (unsigned short) (original - interval) > original)
  {
    return bound;
  }
  return ushort_max(original - interval,bound);
}

unsigned short increase(unsigned short original, unsigned short interval, unsigned short bound)
{
  if ( (unsigned short) (original + interval) < original)
  {
    return bound;
  }
  return ushort_min(original + interval,bound);
}