Average function using Variadic Functions method

rikki cattermole rikki at cattermole.co.nz
Tue Nov 2 16:29:07 UTC 2021


You probably don't want to be using C variadics.

Instead try the typed one:

float mean(float[] input...) {
	// you don't want to divide by zero
	if (input.length == 0)
		return 0;

	float temp = 0;
	// floats and double initialize to NaN by default, not zero.
	
	foreach(value; input) {
		temp += value;
	}

	return temp / input.length;
}


More information about the Digitalmars-d-learn mailing list