Changeset d3b7937 for src/examples/sum.c


Ignore:
Timestamp:
Jan 29, 2016, 4:36:39 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

building runtime library (first attempt)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/sum.c

    rf3fc8cbe rd3b7937  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan  4 07:40:24 2016
    13 // Update Count     : 126
     12// Last Modified On : Thu Jan 28 17:05:53 2016
     13// Update Count     : 130
    1414//
    1515
    16 #include "fstream.h"
     16#include <fstream>
    1717
    1818context sumable( type T ) {
     
    2222        T ++?( T * );
    2323        T ?++( T * );
    24 };
     24}; // sumable
    2525
    2626forall( type T | sumable( T ) )
     
    3030                total += a[i];                                                                  // select +
    3131        return total;
    32 }
     32} // sum
    3333
    3434// Required to satisfy sumable as char does not have addition.
     
    6161                 | sum( size, (int *)a ) | ", check " | (int)s | endl;
    6262
     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
    6372        double s = 0.0, a[size];
    6473        double v = low / 10.0;
     
    6978        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    7079                 | 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
    8181
    8282// Local Variables: //
    8383// tab-width: 4 //
    84 // compile-command: "cfa sum.c fstream.o iostream.o iterator.o" //
     84// compile-command: "cfa sum.c" //
    8585// End: //
Note: See TracChangeset for help on using the changeset viewer.