Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / hello_world / misc_math.c
1 /*
2  * Copyright 2010 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /*
8  * Test basic floating point operations
9  */
10 #include <assert.h>
11 #include <math.h>
12 #include <stdio.h>
13
14 #define NUM_ARRAY_ELEMENTS 3
15
16 float Numbers1[NUM_ARRAY_ELEMENTS] = {0.5, 0.3, 0.2};
17
18
19 int main(int argc, char* argv[]) {
20   int i;
21   float sum;
22
23   /* This will not happen but helps confusing the optimizer */
24   if (argc > 1000) {
25     for (i = 0; i < NUM_ARRAY_ELEMENTS; ++i) {
26       Numbers1[i] = (float) argv[i][0];
27     }
28   }
29
30     /* actual computation */
31   sum = 0.0;
32   for (i = 0; i < NUM_ARRAY_ELEMENTS; ++i) {
33     sum += Numbers1[i];
34   }
35
36   assert (fabs (sum - 1.) < 0.001);
37   return 0;
38 }