function compareTo() {
  var set;
  if (compareTo.arguments.length == 2)
   {
    set = compareTo.arguments[1];
   }
  else if (compareTo.arguments.length == 1)
   {
    set = this.plainMC;
   }
  else
   {
    throw "compareTo(): " + compareTo.arguments.length + " arguments given; expected 1 or 2";
   }
  var rhs = compareTo.arguments[0];
  //--int thislength=0;
  var thislength=0;
  //--int i=0;
  var i=0;
  //--com.ibm.icu.math.BigDecimal newrhs;
  var newrhs;
  // rhs=null will raise NullPointerException, as per Comparable interface
  if (set.lostDigits)
   this.checkdigits(rhs,set.digits);
  // [add will recheck in slowpath cases .. but would report -rhs]
  if ((this.ind==rhs.ind)&&(this.exp==rhs.exp))
   {
    /* sign & exponent the same [very common] */
    thislength=this.mant.length;
    if (thislength<rhs.mant.length)
     return -this.ind;
    if (thislength>rhs.mant.length)
     return this.ind;
    /* lengths are the same; we can do a straight mantissa compare
       unless maybe rounding [rounding is very unusual] */
    if ((thislength<=set.digits)||(set.digits==0))
     {
      {var $6=thislength;i=0;i:for(;$6>0;$6--,i++){
       if (this.mant[i]<rhs.mant[i])
        return -this.ind;
       if (this.mant[i]>rhs.mant[i])
        return this.ind;
       }
      }/*i*/
      return 0; // identical
     }
   /* drop through for full comparison */
   }
  else
   {
    /* More fastpaths possible */
    if (this.ind<rhs.ind)
     return -1;
    if (this.ind>rhs.ind)
     return 1;
   }
  /* carry out a subtract to make the comparison */
  newrhs=this.clone(rhs); // safe copy
  newrhs.ind=-newrhs.ind; // prepare to subtract
  return this.add(newrhs,set).ind; // add, and return sign of result
  }
Compares this <code>BigDecimal</code> to another.
<p>
Implements numeric comparison,
(as defined in the decimal documentation, see {@link BigDecimal
class header}),
and returns a result of type <code>int</code>.
<p>
The result will be:
<table cellpadding=2><tr>
<td align=right><b>-1</b></td>
<td>if the current object is less than the first parameter</td>
</tr><tr>
<td align=right><b>0</b></td>
<td>if the current object is equal to the first parameter</td>
</tr><tr>
<td align=right><b>1</b></td>
<td>if the current object is greater than the first parameter.</td>
</tr></table>
<p>
A {@link #compareTo(Object)} method is also provided.

@param  rhs The <code>BigDecimal</code> for the right hand side of
            the comparison.
@param  set The <code>MathContext</code> arithmetic settings.
@return     An <code>int</code> whose value is -1, 0, or 1 as
            <code>this</code> is numerically less than, equal to,
            or greater than <code>rhs</code>.
@see    #compareTo(Object)
@stable ICU 2.0