Average function using Variadic Functions method
pascal111
judas.the.messiah.111 at gmail.com
Tue Nov 2 16:35:40 UTC 2021
On Tuesday, 2 November 2021 at 16:29:07 UTC, rikki cattermole
wrote:
> 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;
> }
"input..." seems nice, where can I get more information about it?
More information about the Digitalmars-d-learn
mailing list