private static final double grad(int hash, double x, double y, double z) {
		hash &= 15;
		double u = hash < 8 ? x : y;
		if ((hash & 1) != 0) {
			u = -u;
		}
		double v;
		if (hash < 4) {
			v = y;
		} else if (hash == 12 || hash == 14) {
			v = x;
		} else {
			v = z;
		}
		if ((hash & 2) != 0) {
			v = -v;
		}
		return u + v;
	}