code: private int compareMagnitude(BigDecimal val) {
          // Match scales, avoid unnecessary inflation
          long ys = val.intCompact;
          long xs = this.intCompact;
          if (xs == 0)
              return (ys == 0) ? 0 : -1;
          if (ys == 0)
              return 1;
  
          long sdiff = (long)this.scale - val.scale;
          if (sdiff != 0) {
              // Avoid matching scales if the (adjusted) exponents differ
              long xae = (long)this.precision() - this.scale;   // [-1]
              long yae = (long)val.precision() - val.scale;     // [-1]
              if (xae < yae)
                  return -1;
              if (xae > yae)
                  return 1;
              BigInteger rb = null;
              if (sdiff < 0) {
                  // The cases sdiff <= Integer.MIN_VALUE intentionally fall through.
                  if ( sdiff > Integer.MIN_VALUE &&
                        (xs == INFLATED ||
                        (xs = longMultiplyPowerTen(xs, (int)-sdiff)) == INFLATED) &&
                       ys == INFLATED) {
                      rb = bigMultiplyPowerTen((int)-sdiff);
                      return rb.compareMagnitude(val.intVal);
                  }
              } else { // sdiff > 0
                  // The cases sdiff > Integer.MAX_VALUE intentionally fall through.
                  if ( sdiff <= Integer.MAX_VALUE &&
                        (ys == INFLATED ||
                        (ys = longMultiplyPowerTen(ys, (int)sdiff)) == INFLATED) &&
                       xs == INFLATED) {
                      rb = val.bigMultiplyPowerTen((int)sdiff);
                      return this.intVal.compareMagnitude(rb);
                  }
              }
          }
          if (xs != INFLATED)
              return (ys != INFLATED) ? longCompareMagnitude(xs, ys) : -1;
          else if (ys != INFLATED)
              return 1;
          else
              return this.intVal.compareMagnitude(val.intVal);
      }
docs: Version of compareTo that ignores sign.