Changes in src/libcfa/rational.c [d1ab5331:45161b4d]
- File:
-
- 1 edited
-
src/libcfa/rational.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational.c
rd1ab5331 r45161b4d 11 11 // Created On : Wed Apr 6 17:54:28 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed May 4 14:16:14201614 // Update Count : 2 513 // Last Modified On : Tue Apr 12 21:26:42 2016 14 // Update Count : 21 15 15 // 16 16 … … 18 18 #include "fstream" 19 19 #include "stdlib" 20 #include "math" // floor21 20 22 21 … … 53 52 // constructors 54 53 55 void ?{}( Rational * r) {56 r { 0, 1 };54 Rational rational() { 55 return (Rational){ 0, 1 }; 57 56 } // rational 58 57 59 void ?{}( Rational * r,long int n ) {60 r { n, 1 };58 Rational rational( long int n ) { 59 return (Rational){ n, 1 }; 61 60 } // rational 62 61 63 void ?{}( Rational * r,long int n, long int d ) {62 Rational rational( long int n, long int d ) { 64 63 long int t = simplify( &n, &d ); // simplify 65 r->numerator = n / t; 66 r->denominator = d / t; 64 return (Rational){ n / t, d / t }; 67 65 } // rational 68 66 … … 173 171 Rational narrow( double f, long int md ) { 174 172 if ( md <= 1 ) { // maximum fractional digits too small? 175 return (Rational){ f, 1}; // truncate fraction 173 Rational t = rational( f, 1 ); // truncate fraction 174 return t; 176 175 } // if 177 176 … … 199 198 k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2]; 200 199 } // for 201 return (Rational){ neg ? -h[1] : h[1], k[1] }; 200 Rational t = rational( neg ? -h[1] : h[1], k[1] ); 201 return t; 202 202 } // narrow 203 203
Note:
See TracChangeset
for help on using the changeset viewer.