Changeset f80e0218 for src/libcfa/rational.c
- Timestamp:
- Jun 30, 2016, 4:32:56 PM (10 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:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (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
-
src/libcfa/rational.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational.c
r1b5c81ed rf80e0218 11 11 // Created On : Wed Apr 6 17:54:28 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Apr 12 21:26:42201614 // Update Count : 2 113 // Last Modified On : Wed May 4 14:16:14 2016 14 // Update Count : 25 15 15 // 16 16 … … 18 18 #include "fstream" 19 19 #include "stdlib" 20 #include "math" // floor 20 21 21 22 … … 52 53 // constructors 53 54 54 Rational rational() {55 r eturn (Rational){ 0, 1 };55 void ?{}( Rational * r ) { 56 r{ 0, 1 }; 56 57 } // rational 57 58 58 Rational rational(long int n ) {59 r eturn (Rational){ n, 1 };59 void ?{}( Rational * r, long int n ) { 60 r{ n, 1 }; 60 61 } // rational 61 62 62 Rational rational(long int n, long int d ) {63 void ?{}( Rational * r, long int n, long int d ) { 63 64 long int t = simplify( &n, &d ); // simplify 64 return (Rational){ n / t, d / t }; 65 r->numerator = n / t; 66 r->denominator = d / t; 65 67 } // rational 66 68 … … 171 173 Rational narrow( double f, long int md ) { 172 174 if ( md <= 1 ) { // maximum fractional digits too small? 173 Rational t = rational( f, 1 ); // truncate fraction 174 return t; 175 return (Rational){ f, 1}; // truncate fraction 175 176 } // if 176 177 … … 198 199 k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2]; 199 200 } // for 200 Rational t = rational( neg ? -h[1] : h[1], k[1] ); 201 return t; 201 return (Rational){ neg ? -h[1] : h[1], k[1] }; 202 202 } // narrow 203 203
Note:
See TracChangeset
for help on using the changeset viewer.