code: protected Number narrowBigDecimal(Object lhs, Object rhs, BigDecimal bigd) {
      if (isNumberable(lhs) || isNumberable(rhs)) {
        try {
          long l = bigd.longValueExact();
          // coerce to int when possible (int being so often used in method parms)
          if (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
            return Integer.valueOf((int) l);
          }
          else {
            return Long.valueOf(l);
          }
        }
        catch (ArithmeticException xa) {
          // ignore, no exact value possible
        }
      }
      return bigd;
    }
docs: Given a BigDecimal, attempt to narrow it to an Integer or Long if it fits
  if one of the arguments is a numberable.
  
  @param lhs
  the left hand side operand that lead to the bigd result
  @param rhs
  the right hand side operand that lead to the bigd result
  @param bigd
  the BigDecimal to narrow
  @return an Integer or Long if narrowing is possible, the original
  BigInteger otherwise