rint function

double rint(
  1. double x
)

Implementation

double rint(double x) {
  if (x.isNaN || x.isInfinite || x == 0.0) return x;
  const twoTo52 = 4503599627370496.0;
  if (x.abs() >= twoTo52) return x;
  if (x > 0) {
    return (x + twoTo52) - twoTo52;
  } else {
    return (x - twoTo52) + twoTo52;
  }
}