code: public int compareTo(BigDecimal val) {
          // Quick path for equal scale and non-inflated case.
          if (scale == val.scale) {
              long xs = intCompact;
              long ys = val.intCompact;
              if (xs != INFLATED && ys != INFLATED)
                  return xs != ys ? ((xs > ys) ? 1 : -1) : 0;
          }
          int xsign = this.signum();
          int ysign = val.signum();
          if (xsign != ysign)
              return (xsign > ysign) ? 1 : -1;
          if (xsign == 0)
              return 0;
          int cmp = compareMagnitude(val);
          return (xsign > 0) ? cmp : -cmp;
      }
docs: Compares this {@code BigDecimal} with the specified
  {@code BigDecimal}.  Two {@code BigDecimal} objects that are
  equal in value but have a different scale (like 2.0 and 2.00)
  are considered equal by this method.  This method is provided
  in preference to individual methods for each of the six boolean
  comparison operators ({@literal <}, ==,
  {@literal >}, {@literal >=}, !=, {@literal <=}).  The
  suggested idiom for performing these comparisons is:
  {@code (x.compareTo(y)} &lt;<i>op</i>&gt; {@code 0)}, where
  &lt;<i>op</i>&gt; is one of the six comparison operators.
  
  @param  val {@code BigDecimal} to which this {@code BigDecimal} is
  to be compared.
  @return -1, 0, or 1 as this {@code BigDecimal} is numerically
  less than, equal to, or greater than {@code val}.