guava/src/com/google/common/math/DoubleMath.java
@GwtIncompatible // #roundIntermediate
  public static int roundToInt(double x, RoundingMode mode) {
    double z = roundIntermediate(x, mode);
    checkInRangeForRoundingInputs(
        z > MIN_INT_AS_DOUBLE - 1.0 & z < MAX_INT_AS_DOUBLE + 1.0, x, mode);
    return (int) z;
  }
@GwtIncompatible // #roundIntermediate
  public static int roundToInt(double x, RoundingMode mode) {
    double z = roundIntermediate(x, mode);
    checkInRangeForRoundingInputs(
        z > MIN_INT_AS_DOUBLE - 1.0 & z < MAX_INT_AS_DOUBLE + 1.0, x, mode);
    return (int) z;
  }
@ GwtIncompatible // #roundIntermediate public static int roundToInt ( double x , RoundingMode mode ) { double z = roundIntermediate ( x , mode ) ; checkInRangeForRoundingInputs ( z > MIN_INT_AS_DOUBLE - 1.0 & z < MAX_INT_AS_DOUBLE + 1.0 , x , mode ) ; return ( int ) z ; }
Returns the {@code int} value that is equal to {@code x} rounded with the specified rounding
mode, if possible.

@throws ArithmeticException if
<ul>
<li>{@code x} is infinite or NaN
<li>{@code x}, after being rounded to a mathematical integer using the specified rounding
mode, is either less than {@code Integer.MIN_VALUE} or greater than {@code
Integer.MAX_VALUE}
<li>{@code x} is not a mathematical integer and {@code mode} is {@link
RoundingMode#UNNECESSARY}
</ul>
Returns the { @code int } value that is equal to { @code x } rounded with the specified rounding mode if possible .