Debian Codegraph @

benchmarks.larceny/src/sumfp.c

raw
1 /* SUMFP -- Compute sum of integers from 0 to 10000 using floating point */
2
3 #include <stdio.h>
4
5 #define FLOAT double
6
7 static FLOAT run (FLOAT n)
8 {
9 FLOAT i = n, sum = 0.;
10
11 while (i >= 0.)
12 {
13 sum = sum+i;
14 i = i-1.;
15 }
16
17 return sum;
18 }
19
20 int main (int argc, char *argv[])
21 {
22 int i;
23 FLOAT result;
24 int n = 10000;
25
26 if (argc > 1)
27 n = atoi (argv[1]);
28
29 for (i=0; i<5000; i++)
30 result = run (n);
31
32 if (result != 50005000.)
33 printf ("*** wrong result ***\n");
34
35 return 0;
36 }