Changeset 933f32f for tests/sum.cfa


Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/sum.cfa

    r6a9d4b4 r933f32f  
    1111// Created On       : Wed May 27 17:56:53 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun Dec 23 23:00:38 2018
    14 // Update Count     : 287
     13// Last Modified On : Sun May 19 11:21:02 2019
     14// Update Count     : 330
    1515//
    1616
    1717#include <fstream.hfa>
    1818#include <stdlib.hfa>
    19 
    20 void ?{}( int & c, zero_t ) { c = 0; }                                  // not in prelude
    2119
    2220trait sumable( otype T ) {
     
    3129T sum( size_t size, T a[] ) {
    3230        T total = 0;                                                                            // initialize by 0 constructor
    33         for ( size_t i = 0; i < size; i += 1 )
     31        for ( i; size )
    3432                total += a[i];                                                                  // select appropriate +
    3533        return total;
    3634} // sum
    3735
    38 // Not in prelude.
    39 unsigned char ?+?( unsigned char t1, unsigned char t2 ) { return (int)t1 + t2; } // cast forces integer addition, otherwise recursion
    40 unsigned char ?+=?( unsigned char & t1, unsigned char t2 ) { t1 = t1 + t2; return t1; }
    41 unsigned char ++?( unsigned char & t ) { t += 1; return t; }
    42 unsigned char ?++( unsigned char & t ) { unsigned char temp = t; t += 1; return temp; }
    43 
    44 // Not in prelude.
    45 void ?{}( unsigned char & c, zero_t ) { c = 0; }
    46 void ?{}( float & f, zero_t ) { f = 0.0; }
    47 void ?{}( double & d, zero_t ) { d = 0.0; }
    48 
    4936int main( void ) {
    5037        const int low = 5, High = 15, size = High - low;
    5138
    52         unsigned char s = 0, a[size], v = (char)low;
    53         for ( int i = 0; i < size; i += 1, v += 1 ) {
     39        signed char s = 0, a[size], v = (char)low;
     40        for ( int i = 0; i < size; i += 1, v += 1hh ) {
    5441                s += v;
    5542                a[i] = v;
    5643        } // for
    5744        sout | "sum from" | low | "to" | High | "is"
    58                  | sum( size, (unsigned char *)a ) | ", check" | (int)s;
     45                 | sum( size, (signed char *)a ) | ", check" | (signed char)s;
     46
     47        unsigned char s = 0, a[size], v = low;
     48        for ( int i = 0; i < size; i += 1, v += 1hhu ) {
     49                s += (unsigned char)v;
     50                a[i] = (unsigned char)v;
     51        } // for
     52        sout | "sum from" | low | "to" | High | "is"
     53                 | sum( size, (unsigned char *)a ) | ", check" | (unsigned char)s;
     54
     55        short int s = 0, a[size], v = low;
     56        for ( int i = 0; i < size; i += 1, v += 1h ) {
     57                s += (short int)v;
     58                a[i] = (short int)v;
     59        } // for
     60        sout | "sum from" | low | "to" | High | "is"
     61                 | sum( size, (short int *)a ) | ", check" | (short int)s;
    5962
    6063        int s = 0, a[size], v = low;
Note: See TracChangeset for help on using the changeset viewer.