1 | // Copyright (c) Microsoft. All rights reserved. |
---|---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
3 | |
4 | #include <stdarg.h> |
5 | #include "native.h" |
6 | |
7 | #ifdef __clang__ |
8 | #pragma clang diagnostic push |
9 | #pragma clang diagnostic ignored "-Wvarargs" |
10 | #endif |
11 | |
12 | MCC_API VType1 sum(float first, ...) { |
13 | VType1 result; |
14 | |
15 | int count = 0; |
16 | float sum = 0.0; |
17 | float val = first; |
18 | va_list args; |
19 | |
20 | // initialize variable arguments. |
21 | va_start(args, first); |
22 | while (val != (float)-1) { |
23 | sum += val; |
24 | count++; |
25 | val = va_arg(args, float); |
26 | } |
27 | // reset variable arguments. |
28 | va_end(args); |
29 | |
30 | result.count = (float)count; |
31 | result.sum = sum; |
32 | result.average = result.sum / result.count; |
33 | |
34 | result.count1 = (float)count; |
35 | result.sum1 = sum; |
36 | result.average1 = result.sum1 / result.count1; |
37 | |
38 | result.count2 = (float)count; |
39 | result.sum2 = sum; |
40 | result.average2 = result.sum2 / result.count2; |
41 | |
42 | result.count3 = (float)count; |
43 | result.sum3 = sum; |
44 | result.average3 = result.sum3 / result.count3; |
45 | |
46 | result.count4 = (float)count; |
47 | result.sum4 = sum; |
48 | result.average4 = result.sum4 / result.count4; |
49 | |
50 | result.count5 = (float)count; |
51 | result.sum5 = sum; |
52 | result.average5 = result.sum5 / result.count5; |
53 | |
54 | return result; |
55 | } |
56 | |
57 | #ifdef __clang__ |
58 | #pragma clang diagnostic pop |
59 | #endif |
60 |