Changeset 4203f71 for src


Ignore:
Timestamp:
May 16, 2017, 10:47:34 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
02153feb, 9c951e3
Parents:
fae2cf8 (diff), 22634b2 (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' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream

    rfae2cf8 r4203f71  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 21 15:57:24 2017
    13 // Update Count     : 102
     12// Last Modified On : Mon May 15 18:11:09 2017
     13// Update Count     : 104
    1414//
    1515
     
    2929}; // ofstream
    3030
     31// private
    3132_Bool sepPrt( ofstream * );
    32 void sepOn( ofstream * );
    33 void sepOff( ofstream * );
    3433void sepReset( ofstream * );
    3534void sepReset( ofstream *, _Bool );
    3635const char * sepGetCur( ofstream * );
    3736void sepSetCur( ofstream *, const char * );
     37
     38// public
     39void sepOn( ofstream * );
     40void sepOff( ofstream * );
     41_Bool sepDisable( ofstream * );
     42_Bool sepEnable( ofstream * );
     43
    3844const char * sepGet( ofstream * );
    3945void sepSet( ofstream *, const char * );
    4046const char * sepGetTuple( ofstream * );
    4147void sepSetTuple( ofstream *, const char * );
    42 _Bool sepDisable( ofstream * );
    43 _Bool sepEnable( ofstream * );
    4448
    4549int fail( ofstream * );
  • src/libcfa/fstream.c

    rfae2cf8 r4203f71  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 23 08:20:41 2017
    13 // Update Count     : 226
     12// Last Modified On : Mon May 15 18:11:11 2017
     13// Update Count     : 234
    1414//
    1515
     
    3838}
    3939
     40// private
    4041_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     42void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
     43void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
     44const char * sepGetCur( ofstream * os ) { return os->sepCur; }
     45void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; }
     46
     47// public
    4148void sepOn( ofstream * os ) { os->sepOnOff = 1; }
    4249void sepOff( ofstream * os ) { os->sepOnOff = 0; }
    43 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    44 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    45 
    46 const char * sepGetCur( ofstream * os ) { return os->sepCur; }
    47 void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; }
    48 
    49 const char * sepGet( ofstream * os ) { return os->separator; }
    50 
    51 void sepSet( ofstream * os, const char * s ) {
    52         assert( s );
    53         strncpy( os->separator, s, separateSize - 1 );
    54         os->separator[separateSize - 1] = '\0';
    55 } // sepSet
    56 
    57 const char * sepGetTuple( ofstream * os ) { return os->tupleSeparator; }
    58 
    59 void sepSetTuple( ofstream * os, const char * s ) {
    60         assert( s );
    61         strncpy( os->tupleSeparator, s, separateSize - 1 );
    62         os->tupleSeparator[separateSize - 1] = '\0';
    63 } // sepSet
    6450
    6551_Bool sepDisable( ofstream *os ) {
     
    7359        _Bool temp = os->sepDefault;
    7460        os->sepDefault = true;
    75         sepReset( os );
     61        if ( os->sepOnOff ) sepReset( os );                                     // start of line ?
    7662        return temp;
    7763} // sepEnable
     64
     65const char * sepGet( ofstream * os ) { return os->separator; }
     66void sepSet( ofstream * os, const char * s ) {
     67        assert( s );
     68        strncpy( os->separator, s, separateSize - 1 );
     69        os->separator[separateSize - 1] = '\0';
     70} // sepSet
     71
     72const char * sepGetTuple( ofstream * os ) { return os->tupleSeparator; }
     73void sepSetTuple( ofstream * os, const char * s ) {
     74        assert( s );
     75        strncpy( os->tupleSeparator, s, separateSize - 1 );
     76        os->tupleSeparator[separateSize - 1] = '\0';
     77} // sepSet
    7878
    7979int fail( ofstream * os ) {
  • src/libcfa/gmp

    rfae2cf8 r4203f71  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 13 22:52:26 2017
    13 // Update Count     : 8
    14 //
    15 
    16 extern "C" {
     12// Last Modified On : Sun May 14 23:47:36 2017
     13// Update Count     : 9
     14//
     15
    1716// https://gmplib.org/gmp-man-6.1.1.pdf
     17
    1818#include <gmp.h>                                                                                // GNU multi-precise integers
    19 // some code for operators "/" and "%" taken from g++ gmpxx.h
    20 }
    2119#include <fstream>                                                                              // sout
    2220
     
    146144Int ?*=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs * rhs; }
    147145
     146// some code for operators "/" and "%" taken from g++ gmpxx.h
    148147Int ?/?( Int dividend, Int divisor ) { Int quotient; mpz_tdiv_q( quotient.mpz, dividend.mpz, divisor.mpz ); return quotient; }
    149148Int ?/?( Int dividend, unsigned long int divisor ) { Int quotient; mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, divisor ); return quotient; }
  • src/libcfa/iostream

    rfae2cf8 r4203f71  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 21 15:57:29 2017
    13 // Update Count     : 104
     12// Last Modified On : Mon May 15 18:08:44 2017
     13// Update Count     : 105
    1414//
    1515
     
    2020
    2121trait ostream( dtype ostype ) {
     22        // private
    2223        _Bool sepPrt( ostype * );                                                       // return separator state (on/off)
    23         void sepOn( ostype * );                                                         // turn separator state on
    24         void sepOff( ostype * );                                                        // turn separator state off
    2524        void sepReset( ostype * );                                                      // set separator state to default state
    2625        void sepReset( ostype *, _Bool );                                       // set separator and default state
    2726        const char * sepGetCur( ostype * );                                     // get current separator string
    2827        void sepSetCur( ostype *, const char * );                       // set current separator string
     28        // public
     29        void sepOn( ostype * );                                                         // turn separator state on
     30        void sepOff( ostype * );                                                        // turn separator state off
     31        _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
     32        _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
     33
    2934        const char * sepGet( ostype * );                                        // get separator string
    3035        void sepSet( ostype *, const char * );                          // set separator to string (15 character maximum)
    3136        const char * sepGetTuple( ostype * );                           // get tuple separator string
    3237        void sepSetTuple( ostype *, const char * );                     // set tuple separator to string (15 character maximum)
    33         _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
    34         _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
    3538
    3639        int fail( ostype * );
  • src/libcfa/rational

    rfae2cf8 r4203f71  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Sun May 14 16:49:13 2017
    15 // Update Count     : 78
     14// Last Modified On : Mon May 15 21:30:12 2017
     15// Update Count     : 90
    1616//
    1717
     
    128128
    129129// conversion
    130 // forall ( otype RationalImpl | arithmetic( RationalImpl ) )
    131 // double widen( Rational(RationalImpl) r );
    132 // forall ( otype RationalImpl | arithmetic( RationalImpl ) )
    133 // Rational(RationalImpl) narrow( double f, RationalImpl md );
     130forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     131double widen( Rational(RationalImpl) r );
     132forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
     133Rational(RationalImpl) narrow( double f, RationalImpl md );
    134134
    135135// I/O
  • src/libcfa/rational.c

    rfae2cf8 r4203f71  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 14 17:25:19 2017
    13 // Update Count     : 131
     12// Last Modified On : Mon May 15 21:29:23 2017
     13// Update Count     : 149
    1414//
    1515
     
    190190// conversion
    191191
    192 // forall ( otype RationalImpl | arithmetic( RationalImpl ) )
    193 // double widen( Rational(RationalImpl) r ) {
    194 //      return (double)r.numerator / (double)r.denominator;
    195 // } // widen
    196 
    197 // // http://www.ics.uci.edu/~eppstein/numth/frap.c
    198 // forall ( otype RationalImpl | arithmetic( RationalImpl ) )
    199 // Rational(RationalImpl) narrow( double f, RationalImpl md ) {
    200 //      if ( md <= 1 ) {                                                                        // maximum fractional digits too small?
    201 //              return (Rational(RationalImpl)){ f, 1};                 // truncate fraction
    202 //      } // if
    203 
    204 //      // continued fraction coefficients
    205 //      RationalImpl m00 = 1, m11 = 1, m01 = 0, m10 = 0;
    206 //      RationalImpl ai, t;
    207 
    208 //      // find terms until denom gets too big
    209 //      for ( ;; ) {
    210 //              ai = (RationalImpl)f;
    211 //        if ( ! (m10 * ai + m11 <= md) ) break;
    212 //              t = m00 * ai + m01;
    213 //              m01 = m00;
    214 //              m00 = t;
    215 //              t = m10 * ai + m11;
    216 //              m11 = m10;
    217 //              m10 = t;
    218 //              t = (double)ai;
    219 //        if ( f == t ) break;                                                          // prevent division by zero
    220 //        f = 1 / (f - (double)t);
    221 //        if ( f > (double)0x7FFFFFFF ) break;                          // representation failure
    222 //      }
    223 //      return (Rational(RationalImpl)){ m00, m10 };
    224 // } // narrow
     192forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     193double widen( Rational(RationalImpl) r ) {
     194        return convert( r.numerator ) / convert( r.denominator );
     195} // widen
     196
     197// http://www.ics.uci.edu/~eppstein/numth/frap.c
     198forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
     199Rational(RationalImpl) narrow( double f, RationalImpl md ) {
     200        if ( md <= (RationalImpl){1} ) {                                        // maximum fractional digits too small?
     201                return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
     202        } // if
     203
     204        // continued fraction coefficients
     205        RationalImpl m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
     206        RationalImpl ai, t;
     207
     208        // find terms until denom gets too big
     209        for ( ;; ) {
     210                ai = convert( f );
     211          if ( ! (m10 * ai + m11 <= md) ) break;
     212                t = m00 * ai + m01;
     213                m01 = m00;
     214                m00 = t;
     215                t = m10 * ai + m11;
     216                m11 = m10;
     217                m10 = t;
     218                double temp = convert( ai );
     219          if ( f == temp ) break;                                                       // prevent division by zero
     220                f = 1 / (f - temp);
     221          if ( f > (double)0x7FFFFFFF ) break;                          // representation failure
     222        } // for
     223        return (Rational(RationalImpl)){ m00, m10 };
     224} // narrow
    225225
    226226
  • src/tests/.expect/rational.txt

    rfae2cf8 r4203f71  
    17173/1
    18184/3
     19conversion
     200.75
     210.142857142857143
     223.14159292035398
     233/4
     241/7
     25355/113
    1926decompose
    2027more tests
  • src/tests/rational.c

    rfae2cf8 r4203f71  
    1010// Created On       : Mon Mar 28 08:43:12 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 14 18:10:28 2017
    13 // Update Count     : 57
     12// Last Modified On : Mon May 15 21:32:22 2017
     13// Update Count     : 64
    1414//
    1515
     
    2323void ?{}( int * this, zero_t ) { *this = 0; }
    2424void ?{}( int * this, one_t ) { *this = 1; }
     25double convert( int i ) { return (double)i; }
     26int convert( double d ) { return (int)d; }
    2527
    2628int main() {
     
    5759        sout | a / b | endl;
    5860
    59 //      sout | "conversion" | endl;
    60 //      a = (Rational(int)){ 3, 4 };
    61 //      sout | widen( a ) | endl;
    62 //      a = (Rational(int)){ 1, 7 };
    63 //      sout | widen( a ) | endl;
    64 //      a = (Rational(int)){ 355, 113 };
    65 //      sout | widen( a ) | endl;
    66 //      sout | narrow( 0.75, 4 ) | endl;
    67 //      sout | narrow( 0.14285714285714, 16 ) | endl;
    68 //      sout | narrow( 3.14159265358979, 256 ) | endl;
     61        sout | "conversion" | endl;
     62        a = (Rational(int)){ 3, 4 };
     63        sout | widen( a ) | endl;
     64        a = (Rational(int)){ 1, 7 };
     65        sout | widen( a ) | endl;
     66        a = (Rational(int)){ 355, 113 };
     67        sout | widen( a ) | endl;
     68        sout | narrow( 0.75, 4 ) | endl;
     69        sout | narrow( 0.14285714285714, 16 ) | endl;
     70        sout | narrow( 3.14159265358979, 256 ) | endl;
    6971
    7072        sout | "decompose" | endl;
Note: See TracChangeset for help on using the changeset viewer.