Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational.c

    r45161b4d rd1ab5331  
    1111// Created On       : Wed Apr  6 17:54:28 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Tue Apr 12 21:26:42 2016
    14 // Update Count     : 21
     13// Last Modified On : Wed May  4 14:16:14 2016
     14// Update Count     : 25
    1515//
    1616
     
    1818#include "fstream"
    1919#include "stdlib"
     20#include "math"                                                                                 // floor
    2021
    2122
     
    5253// constructors
    5354
    54 Rational rational() {
    55     return (Rational){ 0, 1 };
     55void ?{}( Rational * r ) {
     56    r{ 0, 1 };
    5657} // rational
    5758
    58 Rational rational( long int n ) {
    59     return (Rational){ n, 1 };
     59void ?{}( Rational * r, long int n ) {
     60    r{ n, 1 };
    6061} // rational
    6162
    62 Rational rational( long int n, long int d ) {
     63void ?{}( Rational * r, long int n, long int d ) {
    6364    long int t = simplify( &n, &d );                                    // simplify
    64     return (Rational){ n / t, d / t };
     65    r->numerator = n / t;
     66        r->denominator = d / t;
    6567} // rational
    6668
     
    171173Rational narrow( double f, long int md ) {
    172174        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
    175176        } // if
    176177
     
    198199                k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2];
    199200        } // 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] };
    202202} // narrow
    203203
Note: See TracChangeset for help on using the changeset viewer.