source: doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cfa

Last change on this file was 80e83b6c, checked in by Peter A. Buhr <pabuhr@…>, 5 days ago

last proofread array chapter

  • Property mode set to 100644
File size: 596 bytes
Line 
1#include <fstream.hfa>
2#include <array.hfa>
3
4//extern "C" { // don't mangle the function name `sum`
5
6#ifdef UNSOUND_BOUND
7 #define BND( correct_limit ) 100
8#else
9 #define BND( correct_limit ) correct_limit
10#endif
11
12
13
14
15
16
17
18
19
20forall( [N] )
21double sum(
22 array(float, N) & x ) {
23 double sum = 0;
24 for ( i;
25 BND( N ) )
26 sum += @x[i]@;
27 return sum;
28}
29
30
31
32
33//} // extern "C"
34
35#ifdef RUNIT
36
37#define EXPSZ 7
38
39
40
41
42
43int main() {
44 array( float, EXPSZ ) x;
45 for ( i; EXPSZ ) x[i] = 0.1 * (i + 1);
46 for ( i; EXPSZ ) sout | "elm" | i | x[i];
47 double sum = sum( x );
48 sout | "sum " | wd( 2, sum );
49}
50
51
52
53#endif
Note: See TracBrowser for help on using the repository browser.