Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational

    r630a82a r3d9b5da  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // rational -- Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number)
    8 //     and the denominator (bottom number) are whole numbers. When creating and computing with rational numbers, results
    9 //     are constantly reduced to keep the numerator and denominator as small as possible.
     7// rational --
    108//
    119// Author           : Peter A. Buhr
    1210// Created On       : Wed Apr  6 17:56:25 2016
    1311// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Fri Apr  8 11:38:27 2016
    15 // Update Count     : 15
     12// Last Modified On : Thu Apr  7 17:23:36 2016
     13// Update Count     : 9
    1614//
    1715
    1816#include "iostream"
    1917
    20 // implementation
    2118struct Rational {
    2219        long int numerator, denominator;                                        // invariant: denominator > 0
    2320}; // Rational
    2421
    25 // constants
    2622extern struct Rational 0;
    2723extern struct Rational 1;
    2824
    29 // constructors
    30 Rational rational();
    31 Rational rational( long int n );
    32 Rational rational( long int n, long int d );
    33 
    34 // getter/setter for numerator/denominator
     25long int gcd( long int a, long int b );
     26long int simplify( long int *n, long int *d );
     27Rational rational();                                                                    // constructor
     28Rational rational( long int n );                                                // constructor
     29Rational rational( long int n, long int d );                    // constructor
    3530long int numerator( Rational r );
    3631long int numerator( Rational r, long int n );
    37 long int denominator( Rational r );
    3832long int denominator( Rational r, long int d );
    39 
    40 // comparison
    4133int ?==?( Rational l, Rational r );
    4234int ?!=?( Rational l, Rational r );
     
    4537int ?>?( Rational l, Rational r );
    4638int ?>=?( Rational l, Rational r );
    47 
    48 // arithmetic
    4939Rational -?( Rational r );
    5040Rational ?+?( Rational l, Rational r );
     
    5242Rational ?*?( Rational l, Rational r );
    5343Rational ?/?( Rational l, Rational r );
    54 
    55 // conversion
    5644double widen( Rational r );
    5745Rational narrow( double f, long int md );
    58 
    59 // I/O
    6046forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
    6147forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
Note: See TracChangeset for help on using the changeset viewer.