Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational.c

    rd1ab5331 r45161b4d  
    1111// Created On       : Wed Apr  6 17:54:28 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed May  4 14:16:14 2016
    14 // Update Count     : 25
     13// Last Modified On : Tue Apr 12 21:26:42 2016
     14// Update Count     : 21
    1515//
    1616
     
    1818#include "fstream"
    1919#include "stdlib"
    20 #include "math"                                                                                 // floor
    2120
    2221
     
    5352// constructors
    5453
    55 void ?{}( Rational * r ) {
    56     r{ 0, 1 };
     54Rational rational() {
     55    return (Rational){ 0, 1 };
    5756} // rational
    5857
    59 void ?{}( Rational * r, long int n ) {
    60     r{ n, 1 };
     58Rational rational( long int n ) {
     59    return (Rational){ n, 1 };
    6160} // rational
    6261
    63 void ?{}( Rational * r, long int n, long int d ) {
     62Rational rational( long int n, long int d ) {
    6463    long int t = simplify( &n, &d );                                    // simplify
    65     r->numerator = n / t;
    66         r->denominator = d / t;
     64    return (Rational){ n / t, d / t };
    6765} // rational
    6866
     
    173171Rational narrow( double f, long int md ) {
    174172        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;
    176175        } // if
    177176
     
    199198                k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2];
    200199        } // 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;
    202202} // narrow
    203203
Note: See TracChangeset for help on using the changeset viewer.