Changeset d83b266 for libcfa


Ignore:
Timestamp:
Jul 26, 2021, 2:42:34 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0a061c0
Parents:
c86ee4c (diff), 98233b3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    rc86ee4c rd83b266  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 13 17:26:32 2021
    13 // Update Count     : 117
     12// Last Modified On : Wed Jul 21 13:31:34 2021
     13// Update Count     : 129
    1414//
    1515
     
    7777// implicit increment, decrement if += defined, and implicit not if != defined
    7878
     79// C11 reference manual Section 6.5.16 (page101): "An assignment expression has the value of the left operand after the
     80// assignment, but is not an lvalue." Hence, return a value not a reference.
    7981static inline {
    80         forall( DT & | { DT & ?+=?( DT &, one_t ); } )
    81         DT & ++?( DT & x ) { return x += 1; }
     82        forall( T | { T ?+=?( T &, one_t ); } )
     83        T ++?( T & x ) { return x += 1; }
    8284
    83         forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
    84         DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; }
     85        forall( T | { T ?+=?( T &, one_t ); } )
     86        T ?++( T & x ) { T tmp = x; x += 1; return tmp; }
    8587
    86         forall( DT & | { DT & ?-=?( DT &, one_t ); } )
    87         DT & --?( DT & x ) { return x -= 1; }
     88        forall( T | { T ?-=?( T &, one_t ); } )
     89        T --?( T & x ) { return x -= 1; }
    8890
    89         forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
    90         DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; }
     91        forall( T | { T ?-=?( T &, one_t ); } )
     92        T ?--( T & x ) { T tmp = x; x -= 1; return tmp; }
    9193
    92         forall( DT & | { int ?!=?( const DT &, zero_t ); } )
    93         int !?( const DT & x ) { return !( x != 0 ); }
     94        forall( T | { int ?!=?( T, zero_t ); } )
     95        int !?( T & x ) { return !( x != 0 ); }
    9496} // distribution
    9597
  • libcfa/src/Makefile.am

    rc86ee4c rd83b266  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Sat Apr 24 09:09:56 2021
    14 ## Update Count     : 254
     13## Last Modified On : Fri Jul 16 16:00:40 2021
     14## Update Count     : 255
    1515###############################################################################
    1616
     
    4545        exception.h \
    4646        gmp.hfa \
     47        math.trait.hfa \
    4748        math.hfa \
    4849        time_t.hfa \
  • libcfa/src/concurrency/locks.cfa

    rc86ee4c rd83b266  
    120120        owner = t;
    121121        recursion_count = ( t ? 1 : 0 );
    122         wait_count--;
     122        if ( t ) wait_count--;
    123123        unpark( t );
    124124}
  • libcfa/src/concurrency/locks.hfa

    rc86ee4c rd83b266  
    276276static inline void  ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; }
    277277static inline void ^?{}( linear_backoff_then_block_lock & this ) {}
     278static inline void ?{}( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void;
     279static inline void ?=?( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void;
    278280
    279281static inline bool internal_try_lock(linear_backoff_then_block_lock & this, size_t & compare_val) with(this) {
  • libcfa/src/fstream.cfa

    rc86ee4c rd83b266  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 28 20:37:53 2021
    13 // Update Count     : 445
     12// Last Modified On : Thu Jul 22 11:34:41 2021
     13// Update Count     : 448
    1414//
    1515
     
    338338
    339339
    340 EHM_VIRTUAL_TABLE(Open_Failure, Open_Failure_main_table);
     340//EHM_VIRTUAL_TABLE(Open_Failure, Open_Failure_main_table);
     341static vtable(Open_Failure) Open_Failure_main_table;
     342
     343// exception I/O constructors
    341344void ?{}( Open_Failure & this, ofstream & ostream ) {
    342345        this.virtual_table = &Open_Failure_main_table;
    343346        this.ostream = &ostream;
    344347        this.tag = 1;
    345 }
     348} // ?{}
     349
    346350void ?{}( Open_Failure & this, ifstream & istream ) {
    347351        this.virtual_table = &Open_Failure_main_table;
    348352        this.istream = &istream;
    349353        this.tag = 0;
    350 }
     354} // ?{}
     355
    351356void throwOpen_Failure( ofstream & ostream ) {
    352357        Open_Failure exc = { ostream };
    353358}
     359
    354360void throwOpen_Failure( ifstream & istream ) {
    355361        Open_Failure exc = { istream };
  • libcfa/src/fstream.hfa

    rc86ee4c rd83b266  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 28 20:37:57 2021
    13 // Update Count     : 230
     12// Last Modified On : Tue Jul 20 21:18:03 2021
     13// Update Count     : 232
    1414//
    1515
     
    148148
    149149
    150 EHM_EXCEPTION(Open_Failure)(
     150exception Open_Failure {
    151151        union {
    152152                ofstream * ostream;
     
    155155        // TEMPORARY: need polymorphic exceptions
    156156        int tag;                                                                                        // 1 => ostream; 0 => istream
    157 );
     157};
    158158
    159159void ?{}( Open_Failure & this, ofstream & );
  • libcfa/src/rational.cfa

    rc86ee4c rd83b266  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb  8 17:56:36 2020
    13 // Update Count     : 187
     12// Last Modified On : Tue Jul 20 16:30:06 2021
     13// Update Count     : 193
    1414//
    1515
     
    1818#include "stdlib.hfa"
    1919
    20 forall( RationalImpl | arithmetic( RationalImpl ) ) {
     20forall( T | Arithmetic( T ) ) {
    2121        // helper routines
    2222
    2323        // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce
    2424        // rationals.  alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
    25         static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
     25        static T gcd( T a, T b ) {
    2626                for ( ;; ) {                                                                    // Euclid's algorithm
    27                         RationalImpl r = a % b;
    28                   if ( r == (RationalImpl){0} ) break;
     27                        T r = a % b;
     28                  if ( r == (T){0} ) break;
    2929                        a = b;
    3030                        b = r;
     
    3333        } // gcd
    3434
    35         static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
    36                 if ( d == (RationalImpl){0} ) {
     35        static T simplify( T & n, T & d ) {
     36                if ( d == (T){0} ) {
    3737                        abort | "Invalid rational number construction: denominator cannot be equal to 0.";
    3838                } // exit
    39                 if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator
     39                if ( d < (T){0} ) { d = -d; n = -n; } // move sign to numerator
    4040                return gcd( abs( n ), d );                                              // simplify
    4141        } // Rationalnumber::simplify
     
    4343        // constructors
    4444
    45         void ?{}( Rational(RationalImpl) & r ) {
    46                 r{ (RationalImpl){0}, (RationalImpl){1} };
    47         } // rational
    48 
    49         void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
    50                 r{ n, (RationalImpl){1} };
    51         } // rational
    52 
    53         void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
    54                 RationalImpl t = simplify( n, d );                              // simplify
     45        void ?{}( Rational(T) & r, zero_t ) {
     46                r{ (T){0}, (T){1} };
     47        } // rational
     48
     49        void ?{}( Rational(T) & r, one_t ) {
     50                r{ (T){1}, (T){1} };
     51        } // rational
     52
     53        void ?{}( Rational(T) & r ) {
     54                r{ (T){0}, (T){1} };
     55        } // rational
     56
     57        void ?{}( Rational(T) & r, T n ) {
     58                r{ n, (T){1} };
     59        } // rational
     60
     61        void ?{}( Rational(T) & r, T n, T d ) {
     62                T t = simplify( n, d );                         // simplify
    5563                r.[numerator, denominator] = [n / t, d / t];
    5664        } // rational
    5765
    58         void ?{}( Rational(RationalImpl) & r, zero_t ) {
    59                 r{ (RationalImpl){0}, (RationalImpl){1} };
    60         } // rational
    61 
    62         void ?{}( Rational(RationalImpl) & r, one_t ) {
    63                 r{ (RationalImpl){1}, (RationalImpl){1} };
    64         } // rational
    65 
    6666        // getter for numerator/denominator
    6767
    68         RationalImpl numerator( Rational(RationalImpl) r ) {
     68        T numerator( Rational(T) r ) {
    6969                return r.numerator;
    7070        } // numerator
    7171
    72         RationalImpl denominator( Rational(RationalImpl) r ) {
     72        T denominator( Rational(T) r ) {
    7373                return r.denominator;
    7474        } // denominator
    7575
    76         [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
     76        [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src ) {
    7777                return dest = src.[ numerator, denominator ];
    7878        } // ?=?
     
    8080        // setter for numerator/denominator
    8181
    82         RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
    83                 RationalImpl prev = r.numerator;
    84                 RationalImpl t = gcd( abs( n ), r.denominator ); // simplify
     82        T numerator( Rational(T) r, T n ) {
     83                T prev = r.numerator;
     84                T t = gcd( abs( n ), r.denominator ); // simplify
    8585                r.[numerator, denominator] = [n / t, r.denominator / t];
    8686                return prev;
    8787        } // numerator
    8888
    89         RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
    90                 RationalImpl prev = r.denominator;
    91                 RationalImpl t = simplify( r.numerator, d );    // simplify
     89        T denominator( Rational(T) r, T d ) {
     90                T prev = r.denominator;
     91                T t = simplify( r.numerator, d );       // simplify
    9292                r.[numerator, denominator] = [r.numerator / t, d / t];
    9393                return prev;
     
    9696        // comparison
    9797
    98         int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     98        int ?==?( Rational(T) l, Rational(T) r ) {
    9999                return l.numerator * r.denominator == l.denominator * r.numerator;
    100100        } // ?==?
    101101
    102         int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     102        int ?!=?( Rational(T) l, Rational(T) r ) {
    103103                return ! ( l == r );
    104104        } // ?!=?
    105105
    106         int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     106        int ?!=?( Rational(T) l, zero_t ) {
     107                return ! ( l == (Rational(T)){ 0 } );
     108        } // ?!=?
     109
     110        int ?<?( Rational(T) l, Rational(T) r ) {
    107111                return l.numerator * r.denominator < l.denominator * r.numerator;
    108112        } // ?<?
    109113
    110         int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     114        int ?<=?( Rational(T) l, Rational(T) r ) {
    111115                return l.numerator * r.denominator <= l.denominator * r.numerator;
    112116        } // ?<=?
    113117
    114         int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     118        int ?>?( Rational(T) l, Rational(T) r ) {
    115119                return ! ( l <= r );
    116120        } // ?>?
    117121
    118         int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     122        int ?>=?( Rational(T) l, Rational(T) r ) {
    119123                return ! ( l < r );
    120124        } // ?>=?
     
    122126        // arithmetic
    123127
    124         Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
    125                 return (Rational(RationalImpl)){ r.numerator, r.denominator };
     128        Rational(T) +?( Rational(T) r ) {
     129                return (Rational(T)){ r.numerator, r.denominator };
    126130        } // +?
    127131
    128         Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
    129                 return (Rational(RationalImpl)){ -r.numerator, r.denominator };
     132        Rational(T) -?( Rational(T) r ) {
     133                return (Rational(T)){ -r.numerator, r.denominator };
    130134        } // -?
    131135
    132         Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     136        Rational(T) ?+?( Rational(T) l, Rational(T) r ) {
    133137                if ( l.denominator == r.denominator ) {                 // special case
    134                         return (Rational(RationalImpl)){ l.numerator + r.numerator, l.denominator };
     138                        return (Rational(T)){ l.numerator + r.numerator, l.denominator };
    135139                } else {
    136                         return (Rational(RationalImpl)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
     140                        return (Rational(T)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
    137141                } // if
    138142        } // ?+?
    139143
    140         Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     144        Rational(T) ?+=?( Rational(T) & l, Rational(T) r ) {
     145                l = l + r;
     146                return l;
     147        } // ?+?
     148
     149        Rational(T) ?+=?( Rational(T) & l, one_t ) {
     150                l = l + (Rational(T)){ 1 };
     151                return l;
     152        } // ?+?
     153
     154        Rational(T) ?-?( Rational(T) l, Rational(T) r ) {
    141155                if ( l.denominator == r.denominator ) {                 // special case
    142                         return (Rational(RationalImpl)){ l.numerator - r.numerator, l.denominator };
     156                        return (Rational(T)){ l.numerator - r.numerator, l.denominator };
    143157                } else {
    144                         return (Rational(RationalImpl)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
     158                        return (Rational(T)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
    145159                } // if
    146160        } // ?-?
    147161
    148         Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    149                 return (Rational(RationalImpl)){ l.numerator * r.numerator, l.denominator * r.denominator };
     162        Rational(T) ?-=?( Rational(T) & l, Rational(T) r ) {
     163                l = l - r;
     164                return l;
     165        } // ?-?
     166
     167        Rational(T) ?-=?( Rational(T) & l, one_t ) {
     168                l = l - (Rational(T)){ 1 };
     169                return l;
     170        } // ?-?
     171
     172        Rational(T) ?*?( Rational(T) l, Rational(T) r ) {
     173                return (Rational(T)){ l.numerator * r.numerator, l.denominator * r.denominator };
    150174        } // ?*?
    151175
    152         Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    153                 if ( r.numerator < (RationalImpl){0} ) {
     176        Rational(T) ?*=?( Rational(T) & l, Rational(T) r ) {
     177                return l = l * r;
     178        } // ?*?
     179
     180        Rational(T) ?/?( Rational(T) l, Rational(T) r ) {
     181                if ( r.numerator < (T){0} ) {
    154182                        r.[numerator, denominator] = [-r.numerator, -r.denominator];
    155183                } // if
    156                 return (Rational(RationalImpl)){ l.numerator * r.denominator, l.denominator * r.numerator };
     184                return (Rational(T)){ l.numerator * r.denominator, l.denominator * r.numerator };
    157185        } // ?/?
    158186
     187        Rational(T) ?/=?( Rational(T) & l, Rational(T) r ) {
     188                return l = l / r;
     189        } // ?/?
     190
    159191        // I/O
    160192
    161         forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    162         istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
     193        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
     194        istype & ?|?( istype & is, Rational(T) & r ) {
    163195                is | r.numerator | r.denominator;
    164                 RationalImpl t = simplify( r.numerator, r.denominator );
     196                T t = simplify( r.numerator, r.denominator );
    165197                r.numerator /= t;
    166198                r.denominator /= t;
     
    168200        } // ?|?
    169201
    170         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
    171                 ostype & ?|?( ostype & os, Rational(RationalImpl) r ) {
     202        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
     203                ostype & ?|?( ostype & os, Rational(T) r ) {
    172204                        return os | r.numerator | '/' | r.denominator;
    173205                } // ?|?
    174206
    175                 void ?|?( ostype & os, Rational(RationalImpl) r ) {
     207                void ?|?( ostype & os, Rational(T) r ) {
    176208                        (ostype &)(os | r); ends( os );
    177209                } // ?|?
     
    179211} // distribution
    180212
    181 forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
    182 Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) {
    183         if ( y < 0 ) {
    184                 return (Rational(RationalImpl)){ x.denominator \ -y, x.numerator \ -y };
    185         } else {
    186                 return (Rational(RationalImpl)){ x.numerator \ y, x.denominator \ y };
    187         } // if
    188 }
     213forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
     214        Rational(T) ?\?( Rational(T) x, long int y ) {
     215                if ( y < 0 ) {
     216                        return (Rational(T)){ x.denominator \ -y, x.numerator \ -y };
     217                } else {
     218                        return (Rational(T)){ x.numerator \ y, x.denominator \ y };
     219                } // if
     220        } // ?\?
     221
     222        Rational(T) ?\=?( Rational(T) & x, long int y ) {
     223                return x = x \ y;
     224        } // ?\?
     225} // distribution
    189226
    190227// conversion
    191228
    192 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    193 double widen( Rational(RationalImpl) r ) {
     229forall( T | Arithmetic( T ) | { double convert( T ); } )
     230double widen( Rational(T) r ) {
    194231        return convert( r.numerator ) / convert( r.denominator );
    195232} // widen
    196233
    197 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
    198 Rational(RationalImpl) narrow( double f, RationalImpl md ) {
     234forall( T | Arithmetic( T ) | { double convert( T ); T convert( double ); } )
     235Rational(T) narrow( double f, T md ) {
    199236        // http://www.ics.uci.edu/~eppstein/numth/frap.c
    200         if ( md <= (RationalImpl){1} ) {                                        // maximum fractional digits too small?
    201                 return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
     237        if ( md <= (T){1} ) {                                   // maximum fractional digits too small?
     238                return (Rational(T)){ convert( f ), (T){1}}; // truncate fraction
    202239        } // if
    203240
    204241        // continued fraction coefficients
    205         RationalImpl m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
    206         RationalImpl ai, t;
     242        T m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
     243        T ai, t;
    207244
    208245        // find terms until denom gets too big
     
    221258          if ( f > (double)0x7FFFFFFF ) break;                          // representation failure
    222259        } // for
    223         return (Rational(RationalImpl)){ m00, m10 };
     260        return (Rational(T)){ m00, m10 };
    224261} // narrow
    225262
  • libcfa/src/rational.hfa

    rc86ee4c rd83b266  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Tue Mar 26 23:16:10 2019
    15 // Update Count     : 109
     14// Last Modified On : Tue Jul 20 17:45:29 2021
     15// Update Count     : 118
    1616//
    1717
     
    1919
    2020#include "iostream.hfa"
    21 
    22 trait scalar( T ) {
    23 };
    24 
    25 trait arithmetic( T | scalar( T ) ) {
    26         int !?( T );
    27         int ?==?( T, T );
    28         int ?!=?( T, T );
    29         int ?<?( T, T );
    30         int ?<=?( T, T );
    31         int ?>?( T, T );
    32         int ?>=?( T, T );
    33         void ?{}( T &, zero_t );
    34         void ?{}( T &, one_t );
    35         T +?( T );
    36         T -?( T );
    37         T ?+?( T, T );
    38         T ?-?( T, T );
    39         T ?*?( T, T );
    40         T ?/?( T, T );
    41         T ?%?( T, T );
    42         T ?/=?( T &, T );
    43         T abs( T );
    44 };
     21#include "math.trait.hfa"                                                               // Arithmetic
    4522
    4623// implementation
    4724
    48 forall( RationalImpl | arithmetic( RationalImpl ) ) {
     25forall( T | Arithmetic( T ) ) {
    4926        struct Rational {
    50                 RationalImpl numerator, denominator;                    // invariant: denominator > 0
     27                T numerator, denominator;                                               // invariant: denominator > 0
    5128        }; // Rational
    5229
    5330        // constructors
    5431
    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 );
     32        void ?{}( Rational(T) & r );
     33        void ?{}( Rational(T) & r, zero_t );
     34        void ?{}( Rational(T) & r, one_t );
     35        void ?{}( Rational(T) & r, T n );
     36        void ?{}( Rational(T) & r, T n, T d );
    6037
    6138        // numerator/denominator getter
    6239
    63         RationalImpl numerator( Rational(RationalImpl) r );
    64         RationalImpl denominator( Rational(RationalImpl) r );
    65         [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
     40        T numerator( Rational(T) r );
     41        T denominator( Rational(T) r );
     42        [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src );
    6643
    6744        // numerator/denominator setter
    6845
    69         RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
    70         RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
     46        T numerator( Rational(T) r, T n );
     47        T denominator( Rational(T) r, T d );
    7148
    7249        // comparison
    7350
    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 );
     51        int ?==?( Rational(T) l, Rational(T) r );
     52        int ?!=?( Rational(T) l, Rational(T) r );
     53        int ?!=?( Rational(T) l, zero_t );                                      // => !
     54        int ?<?( Rational(T) l, Rational(T) r );
     55        int ?<=?( Rational(T) l, Rational(T) r );
     56        int ?>?( Rational(T) l, Rational(T) r );
     57        int ?>=?( Rational(T) l, Rational(T) r );
    8058
    8159        // arithmetic
    8260
    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 );
     61        Rational(T) +?( Rational(T) r );
     62        Rational(T) -?( Rational(T) r );
     63        Rational(T) ?+?( Rational(T) l, Rational(T) r );
     64        Rational(T) ?+=?( Rational(T) & l, Rational(T) r );
     65        Rational(T) ?+=?( Rational(T) & l, one_t );                     // => ++?, ?++
     66        Rational(T) ?-?( Rational(T) l, Rational(T) r );
     67        Rational(T) ?-=?( Rational(T) & l, Rational(T) r );
     68        Rational(T) ?-=?( Rational(T) & l, one_t );                     // => --?, ?--
     69        Rational(T) ?*?( Rational(T) l, Rational(T) r );
     70        Rational(T) ?*=?( Rational(T) & l, Rational(T) r );
     71        Rational(T) ?/?( Rational(T) l, Rational(T) r );
     72        Rational(T) ?/=?( Rational(T) & l, Rational(T) r );
    8973
    9074        // I/O
    91         forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    92         istype & ?|?( istype &, Rational(RationalImpl) & );
     75        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
     76        istype & ?|?( istype &, Rational(T) & );
    9377
    94         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
    95                 ostype & ?|?( ostype &, Rational(RationalImpl) );
    96                 void ?|?( ostype &, Rational(RationalImpl) );
     78        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
     79                ostype & ?|?( ostype &, Rational(T) );
     80                void ?|?( ostype &, Rational(T) );
    9781        } // distribution
    9882} // distribution
    9983
    100 forall( RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )
    101 Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y );
     84forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
     85        Rational(T) ?\?( Rational(T) x, long int y );
     86        Rational(T) ?\=?( Rational(T) & x, long int y );
     87} // distribution
    10288
    10389// conversion
    104 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    105 double widen( Rational(RationalImpl) r );
    106 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
    107 Rational(RationalImpl) narrow( double f, RationalImpl md );
     90forall( T | Arithmetic( T ) | { double convert( T ); } )
     91double widen( Rational(T) r );
     92forall( T | Arithmetic( T ) | { double convert( T );  T convert( double );} )
     93Rational(T) narrow( double f, T md );
    10894
    10995// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.