Changeset d1ab5331 for src/libcfa
- Timestamp:
- May 4, 2016, 2:24:23 PM (8 years ago)
- 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, with_gc
- Children:
- 99ee64d
- Parents:
- a1d6d80
- Location:
- src/libcfa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational
ra1d6d80 rd1ab5331 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Apr 8 11:38:27201615 // Update Count : 1 514 // Last Modified On : Wed May 4 14:11:45 2016 15 // Update Count : 16 16 16 // 17 17 … … 28 28 29 29 // constructors 30 Rational rational();31 Rational rational(long int n );32 Rational rational(long int n, long int d );30 void ?{}( Rational * r ); 31 void ?{}( Rational * r, long int n ); 32 void ?{}( Rational * r, long int n, long int d ); 33 33 34 34 // getter/setter for numerator/denominator -
src/libcfa/rational.c
ra1d6d80 rd1ab5331 11 11 // Created On : Wed Apr 6 17:54:28 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Thu Apr 21 07:33:03201614 // Update Count : 2 213 // Last Modified On : Wed May 4 14:16:14 2016 14 // Update Count : 25 15 15 // 16 16 … … 53 53 // constructors 54 54 55 Rational rational() {56 r eturn (Rational){ 0, 1 };55 void ?{}( Rational * r ) { 56 r{ 0, 1 }; 57 57 } // rational 58 58 59 Rational rational(long int n ) {60 r eturn (Rational){ n, 1 };59 void ?{}( Rational * r, long int n ) { 60 r{ n, 1 }; 61 61 } // rational 62 62 63 Rational rational(long int n, long int d ) {63 void ?{}( Rational * r, long int n, long int d ) { 64 64 long int t = simplify( &n, &d ); // simplify 65 return (Rational){ n / t, d / t }; 65 r->numerator = n / t; 66 r->denominator = d / t; 66 67 } // rational 67 68 … … 172 173 Rational narrow( double f, long int md ) { 173 174 if ( md <= 1 ) { // maximum fractional digits too small? 174 Rational t = rational( f, 1 ); // truncate fraction 175 return t; 175 return (Rational){ f, 1}; // truncate fraction 176 176 } // if 177 177 … … 199 199 k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2]; 200 200 } // for 201 Rational t = rational( neg ? -h[1] : h[1], k[1] ); 202 return t; 201 return (Rational){ neg ? -h[1] : h[1], k[1] }; 203 202 } // narrow 204 203
Note: See TracChangeset
for help on using the changeset viewer.