code: public double d(float[] x, float[] y) {
          if (x.length != y.length)
              throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
  
          int n = x.length;
          int m = 0;
          double dist = 0.0;
  
          if (weight == null) {
              for (int i = 0; i < n; i++) {
                  if (!Float.isNaN(x[i]) && !Float.isNaN(y[i])) {
                      m++;
                      double d = x[i] - y[i];
                      dist += d * d;
                  }
              }
          } else {
              if (x.length != weight.length)
                  throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length));
  
              for (int i = 0; i < n; i++) {
                  if (!Float.isNaN(x[i]) && !Float.isNaN(y[i])) {
                      m++;
                      double d = x[i] - y[i];
                      dist += weight[i] * d * d;
                  }
              }
          }
  
          if (m == 0)
              dist = Double.NaN;
          else
              dist = n * dist / m;
  
  
          return Math.sqrt(dist);
      }
docs: Euclidean distance between the two arrays of type float.
  NaN will be treated as missing values and will be excluded from the
  calculation. Let m be the number nonmissing values, and n be the
  number of all values. The returned distance is sqrt(n * d / m),
  where d is the square of distance between nonmissing values.