Here you can find the source of avg(double values[], int size, boolean ignoreNan)
public final static double avg(double values[], int size, boolean ignoreNan)
//package com.java2s; //License from project: Apache License public class Main { public final static double avg(double values[], int size, boolean ignoreNan) { if (values == null || size == 0) { return Double.NaN; }/*w w w. j a v a2s .c o m*/ int cnt = 0; double sum = 0; for (int i = 0; i < size; i++) { double v = values[i]; if (!Double.isNaN(v)) { cnt++; sum += v; } else if (!ignoreNan) { cnt++; } } return cnt == 0 ? Double.NaN : sum / cnt; } }