Java tutorial
//package com.java2s; //License from project: BSD License public class Main { public static void normalize2(double[] x) { double sum = 0; for (int i = 0; i < x.length; i++) if (!Double.isNaN(x[i])) sum += x[i] * x[i]; if (sum == 0) return; double f = 1.0 / Math.sqrt(sum); for (int i = 0; i < x.length; i++) if (!Double.isNaN(x[i])) x[i] *= f; } }