Changes in src/libcfa/rational [53a6c2a:6c6455f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational
r53a6c2a r6c6455f 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Jul 7 09:34:33201715 // Update Count : 9 314 // Last Modified On : Mon May 15 21:30:12 2017 15 // Update Count : 90 16 16 // 17 17 18 #pragma once 18 #ifndef RATIONAL_H 19 #define RATIONAL_H 19 20 20 21 #include "iostream" … … 46 47 // implementation 47 48 48 forall ( otype RationalImpl | arithmetic( RationalImpl ) )49 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 49 50 struct Rational { 50 51 RationalImpl numerator, denominator; // invariant: denominator > 0 … … 53 54 // constructors 54 55 55 forall ( otype RationalImpl | arithmetic( RationalImpl ) )56 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 56 57 void ?{}( Rational(RationalImpl) * r ); 57 58 58 forall ( otype RationalImpl | arithmetic( RationalImpl ) )59 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 59 60 void ?{}( Rational(RationalImpl) * r, RationalImpl n ); 60 61 61 forall ( otype RationalImpl | arithmetic( RationalImpl ) )62 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 62 63 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ); 63 64 64 forall ( otype RationalImpl | arithmetic( RationalImpl ) )65 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 65 66 void ?{}( Rational(RationalImpl) * r, zero_t ); 66 67 67 forall ( otype RationalImpl | arithmetic( RationalImpl ) )68 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 68 69 void ?{}( Rational(RationalImpl) * r, one_t ); 69 70 70 // numerator/denominator getter71 // getter for numerator/denominator 71 72 72 forall ( otype RationalImpl | arithmetic( RationalImpl ) )73 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 73 74 RationalImpl numerator( Rational(RationalImpl) r ); 74 75 75 forall ( otype RationalImpl | arithmetic( RationalImpl ) )76 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 76 77 RationalImpl denominator( Rational(RationalImpl) r ); 77 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 78 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 79 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 80 80 81 // numerator/denominator setter81 // setter for numerator/denominator 82 82 83 forall ( otype RationalImpl | arithmetic( RationalImpl ) )83 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 84 84 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ); 85 85 86 forall ( otype RationalImpl | arithmetic( RationalImpl ) )86 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 87 87 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ); 88 88 89 89 // comparison 90 90 91 forall ( otype RationalImpl | arithmetic( RationalImpl ) )91 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 92 92 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 93 93 94 forall ( otype RationalImpl | arithmetic( RationalImpl ) )94 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 95 95 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 96 96 97 forall ( otype RationalImpl | arithmetic( RationalImpl ) )97 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 98 98 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 99 99 100 forall ( otype RationalImpl | arithmetic( RationalImpl ) )100 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 101 101 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 102 102 103 forall ( otype RationalImpl | arithmetic( RationalImpl ) )103 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 104 104 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 105 105 106 forall ( otype RationalImpl | arithmetic( RationalImpl ) )106 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 107 107 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 108 108 109 109 // arithmetic 110 110 111 forall ( otype RationalImpl | arithmetic( RationalImpl ) )111 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 112 112 Rational(RationalImpl) +?( Rational(RationalImpl) r ); 113 113 114 forall ( otype RationalImpl | arithmetic( RationalImpl ) )114 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 115 115 Rational(RationalImpl) -?( Rational(RationalImpl) r ); 116 116 117 forall ( otype RationalImpl | arithmetic( RationalImpl ) )117 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 118 118 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 119 119 120 forall ( otype RationalImpl | arithmetic( RationalImpl ) )120 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 121 121 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 122 122 123 forall ( otype RationalImpl | arithmetic( RationalImpl ) )123 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 124 124 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 125 125 126 forall ( otype RationalImpl | arithmetic( RationalImpl ) )126 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 127 127 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 128 128 129 129 // conversion 130 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )130 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 131 131 double widen( Rational(RationalImpl) r ); 132 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} )132 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} ) 133 133 Rational(RationalImpl) narrow( double f, RationalImpl md ); 134 134 135 135 // I/O 136 forall ( otype RationalImpl | arithmetic( RationalImpl ) )136 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 137 137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } ) 138 138 istype * ?|?( istype *, Rational(RationalImpl) * ); 139 139 140 forall ( otype RationalImpl | arithmetic( RationalImpl ) )140 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 141 141 forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } ) 142 142 ostype * ?|?( ostype *, Rational(RationalImpl ) ); 143 144 #endif // RATIONAL_H 143 145 144 146 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.