code: public static double rint(double x) {
          double y = floor(x);
          double d = x - y;
  
          if (d > 0.5) {
              if (y == -1.0) {
                  return -0.0; // Preserve sign of operand
              }
              return y+1.0;
          }
          if (d < 0.5) {
              return y;
          }
  
          /* half way, round to even */
          long z = (long) y;
          return (z & 1) == 0 ? y : y + 1.0;
      }
docs: Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.
  @param x number from which nearest whole number is requested
  @return a double number r such that r is an integer r - 0.5 <= x <= r + 0.5