Changeset f676b84 for src/libcfa/rational.c
- Timestamp:
- Aug 25, 2017, 10:47:42 AM (7 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational.c
rddf8a29 rf676b84 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 16 18:35:36201713 // Update Count : 15 012 // Last Modified On : Wed Aug 23 22:38:48 2017 13 // Update Count : 154 14 14 // 15 15 … … 34 34 35 35 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 36 static RationalImpl simplify( RationalImpl * n, RationalImpl *d ) {37 if ( *d == (RationalImpl){0} ) {36 static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) { 37 if ( d == (RationalImpl){0} ) { 38 38 serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl; 39 39 exit( EXIT_FAILURE ); 40 40 } // exit 41 if ( *d < (RationalImpl){0} ) { *d = -*d; *n = -*n; }// move sign to numerator42 return gcd( abs( *n ), *d );// simplify41 if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator 42 return gcd( abs( n ), d ); // simplify 43 43 } // Rationalnumber::simplify 44 44 … … 58 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 59 59 void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) { 60 RationalImpl t = simplify( &n, &d );// simplify60 RationalImpl t = simplify( n, d ); // simplify 61 61 r.numerator = n / t; 62 62 r.denominator = d / t; … … 95 95 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) { 96 96 RationalImpl prev = r.denominator; 97 RationalImpl t = simplify( &r.numerator, &d ); // simplify97 RationalImpl t = simplify( r.numerator, d ); // simplify 98 98 r.numerator = r.numerator / t; 99 99 r.denominator = d / t; … … 228 228 229 229 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl *); } )231 istype * ?|?( istype * is, Rational(RationalImpl) *r ) {230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } ) 231 istype * ?|?( istype * is, Rational(RationalImpl) & r ) { 232 232 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; 237 237 return is; 238 238 } // ?|?
Note: See TracChangeset
for help on using the changeset viewer.