Changes in src/libcfa/rational.c [45161b4d:d1ab5331]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational.c
r45161b4d rd1ab5331 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.