Ignore:
Timestamp:
Aug 25, 2017, 10:47:42 AM (7 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:
19a9822, 6b224a52, f22b7aef
Parents:
ddf8a29 (diff), 3eab308c (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational.c

    rddf8a29 rf676b84  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 16 18:35:36 2017
    13 // Update Count     : 150
     12// Last Modified On : Wed Aug 23 22:38:48 2017
     13// Update Count     : 154
    1414//
    1515
     
    3434
    3535forall( otype RationalImpl | arithmetic( RationalImpl ) )
    36 static RationalImpl simplify( RationalImpl * n, RationalImpl * d ) {
    37         if ( *d == (RationalImpl){0} ) {
     36static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
     37        if ( d == (RationalImpl){0} ) {
    3838                serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
    3939                exit( EXIT_FAILURE );
    4040        } // exit
    41         if ( *d < (RationalImpl){0} ) { *d = -*d; *n = -*n; } // move sign to numerator
    42         return gcd( abs( *n ), *d );                                            // simplify
     41        if ( d < (RationalImpl){0} ) { d = -d; n = -n; }        // move sign to numerator
     42        return gcd( abs( n ), d );                                                      // simplify
    4343} // Rationalnumber::simplify
    4444
     
    5858forall( otype RationalImpl | arithmetic( RationalImpl ) )
    5959void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
    60         RationalImpl t = simplify( &n, &d );                            // simplify
     60        RationalImpl t = simplify( n, d );                                      // simplify
    6161        r.numerator = n / t;
    6262        r.denominator = d / t;
     
    9595RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
    9696        RationalImpl prev = r.denominator;
    97         RationalImpl t = simplify( &r.numerator, &d );                  // simplify
     97        RationalImpl t = simplify( r.numerator, d );                    // simplify
    9898        r.numerator = r.numerator / t;
    9999        r.denominator = d / t;
     
    228228
    229229forall( otype RationalImpl | arithmetic( RationalImpl ) )
    230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
    231 istype * ?|?( istype * is, Rational(RationalImpl) * r ) {
     230forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } )
     231istype * ?|?( istype * is, Rational(RationalImpl) & r ) {
    232232        RationalImpl t;
    233         is | &(r->numerator) | &(r->denominator);
    234         t = simplify( &(r->numerator), &(r->denominator) );
    235         r->numerator /= t;
    236         r->denominator /= t;
     233        is | r.numerator | r.denominator;
     234        t = simplify( r.numerator, r.denominator );
     235        r.numerator /= t;
     236        r.denominator /= t;
    237237        return is;
    238238} // ?|?
Note: See TracChangeset for help on using the changeset viewer.