Changeset d3b7937 for src/examples/sum.c
- Timestamp:
- Jan 29, 2016, 4:36:39 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- ae8b942
- Parents:
- f3fc8cbe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/sum.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 07:40:24201613 // Update Count : 1 2612 // Last Modified On : Thu Jan 28 17:05:53 2016 13 // Update Count : 130 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 context sumable( type T ) { … … 22 22 T ++?( T * ); 23 23 T ?++( T * ); 24 }; 24 }; // sumable 25 25 26 26 forall( type T | sumable( T ) ) … … 30 30 total += a[i]; // select + 31 31 return total; 32 } 32 } // sum 33 33 34 34 // Required to satisfy sumable as char does not have addition. … … 61 61 | sum( size, (int *)a ) | ", check " | (int)s | endl; 62 62 63 float s = 0.0, a[size]; 64 float v = low / 10.0; 65 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 66 s += (float)v; 67 a[i] = (float)v; 68 } 69 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 70 | sum( size, (float *)a ) | ", check " | (float)s | endl; 71 63 72 double s = 0.0, a[size]; 64 73 double v = low / 10.0; … … 69 78 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 70 79 | sum( size, (double *)a ) | ", check " | (double)s | endl; 71 72 float s = 0.0, a[size]; 73 float v = low / 10.0; 74 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 75 s += (float)v; 76 a[i] = (float)v; 77 } 78 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 79 | sum( size, (float *)a ) | ", check " | (float)s | endl; 80 } 80 } // main 81 81 82 82 // Local Variables: // 83 83 // tab-width: 4 // 84 // compile-command: "cfa sum.c fstream.o iostream.o iterator.o" //84 // compile-command: "cfa sum.c" // 85 85 // End: //
Note: See TracChangeset
for help on using the changeset viewer.