round static method

int round(
  1. double d
)

Ends up being a bit faster than {@link Math#round(double)}. This merely rounds its argument to the nearest int, where x.5 rounds up to x+1. Semantics of this shortcut differ slightly from {@link Math#round(double)} in that half rounds down for negative values. -2.5 rounds to -3, not -2. For purposes here it makes no difference.

@param d real value to round @return nearest int

Implementation

static int round(double d) {
  if (d.isNaN) return 0;
  if (d.isInfinite) {
    if (d.sign == 1) {
      return maxValue;
    } else {
      return minValue;
    }
  }
  return (d + (d < 0.0 ? -0.5 : 0.5)).toInt();
}