Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational

    r3ce0d440 r09687aa  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Sat Jun  2 09:10:01 2018
    15 // Update Count     : 105
     14// Last Modified On : Wed Dec  6 23:12:53 2017
     15// Update Count     : 97
    1616//
    1717
     
    4646// implementation
    4747
    48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
    49         struct Rational {
    50                 RationalImpl numerator, denominator;                    // invariant: denominator > 0
    51         }; // Rational
     48forall( otype RationalImpl | arithmetic( RationalImpl ) )
     49struct Rational {
     50        RationalImpl numerator, denominator;                            // invariant: denominator > 0
     51}; // Rational
    5252
    53         // constructors
     53// constructors
    5454
    55         void ?{}( Rational(RationalImpl) & r );
    56         void ?{}( Rational(RationalImpl) & r, RationalImpl n );
    57         void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
    58         void ?{}( Rational(RationalImpl) & r, zero_t );
    59         void ?{}( Rational(RationalImpl) & r, one_t );
     55forall( otype RationalImpl | arithmetic( RationalImpl ) )
     56void ?{}( Rational(RationalImpl) & r );
    6057
    61         // numerator/denominator getter
     58forall( otype RationalImpl | arithmetic( RationalImpl ) )
     59void ?{}( Rational(RationalImpl) & r, RationalImpl n );
    6260
    63         RationalImpl numerator( Rational(RationalImpl) r );
    64         RationalImpl denominator( Rational(RationalImpl) r );
    65         [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
     61forall( otype RationalImpl | arithmetic( RationalImpl ) )
     62void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
    6663
    67         // numerator/denominator setter
     64forall( otype RationalImpl | arithmetic( RationalImpl ) )
     65void ?{}( Rational(RationalImpl) & r, zero_t );
    6866
    69         RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
    70         RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
     67forall( otype RationalImpl | arithmetic( RationalImpl ) )
     68void ?{}( Rational(RationalImpl) & r, one_t );
    7169
    72         // comparison
     70// numerator/denominator getter
    7371
    74         int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    75         int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    76         int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    77         int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    78         int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    79         int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     72forall( otype RationalImpl | arithmetic( RationalImpl ) )
     73RationalImpl numerator( Rational(RationalImpl) r );
    8074
    81         // arithmetic
     75forall( otype RationalImpl | arithmetic( RationalImpl ) )
     76RationalImpl denominator( Rational(RationalImpl) r );
    8277
    83         Rational(RationalImpl) +?( Rational(RationalImpl) r );
    84         Rational(RationalImpl) -?( Rational(RationalImpl) r );
    85         Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    86         Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    87         Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    88         Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     78forall( otype RationalImpl | arithmetic( RationalImpl ) )
     79[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
    8980
    90         // I/O
    91         forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    92         istype & ?|?( istype &, Rational(RationalImpl) & );
     81// numerator/denominator setter
    9382
    94         forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
    95         ostype & ?|?( ostype &, Rational(RationalImpl ) );
    96 } // distribution
     83forall( otype RationalImpl | arithmetic( RationalImpl ) )
     84RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
     85
     86forall( otype RationalImpl | arithmetic( RationalImpl ) )
     87RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
     88
     89// comparison
     90
     91forall( otype RationalImpl | arithmetic( RationalImpl ) )
     92int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     93
     94forall( otype RationalImpl | arithmetic( RationalImpl ) )
     95int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     96
     97forall( otype RationalImpl | arithmetic( RationalImpl ) )
     98int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     99
     100forall( otype RationalImpl | arithmetic( RationalImpl ) )
     101int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     102
     103forall( otype RationalImpl | arithmetic( RationalImpl ) )
     104int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     105
     106forall( otype RationalImpl | arithmetic( RationalImpl ) )
     107int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     108
     109// arithmetic
     110
     111forall( otype RationalImpl | arithmetic( RationalImpl ) )
     112Rational(RationalImpl) +?( Rational(RationalImpl) r );
     113
     114forall( otype RationalImpl | arithmetic( RationalImpl ) )
     115Rational(RationalImpl) -?( Rational(RationalImpl) r );
     116
     117forall( otype RationalImpl | arithmetic( RationalImpl ) )
     118Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     119
     120forall( otype RationalImpl | arithmetic( RationalImpl ) )
     121Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     122
     123forall( otype RationalImpl | arithmetic( RationalImpl ) )
     124Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     125
     126forall( otype RationalImpl | arithmetic( RationalImpl ) )
     127Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    97128
    98129// conversion
     
    102133Rational(RationalImpl) narrow( double f, RationalImpl md );
    103134
     135// I/O
     136forall( otype RationalImpl | arithmetic( RationalImpl ) )
     137forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     138istype & ?|?( istype &, Rational(RationalImpl) & );
     139
     140forall( otype RationalImpl | arithmetic( RationalImpl ) )
     141forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
     142ostype & ?|?( ostype &, Rational(RationalImpl ) );
     143
    104144// Local Variables: //
    105145// mode: c //
Note: See TracChangeset for help on using the changeset viewer.