Changeset 3ce0d440 for src/libcfa/rational
- Timestamp:
- Jun 2, 2018, 10:00:29 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 428bef8
- Parents:
- d56cc219
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/rational
rd56cc219 r3ce0d440 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Wed Dec 6 23:12:53 201715 // Update Count : 9714 // Last Modified On : Sat Jun 2 09:10:01 2018 15 // Update Count : 105 16 16 // 17 17 … … 46 46 // implementation 47 47 48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 49 struct Rational {50 RationalImpl numerator, denominator;// invariant: denominator > 051 }; // Rational48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) { 49 struct Rational { 50 RationalImpl numerator, denominator; // invariant: denominator > 0 51 }; // Rational 52 52 53 // constructors53 // constructors 54 54 55 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 56 void ?{}( Rational(RationalImpl) & r ); 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 ); 57 60 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 59 void ?{}( Rational(RationalImpl) & r, RationalImpl n ); 61 // numerator/denominator getter 60 62 61 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 62 void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ); 63 RationalImpl numerator( Rational(RationalImpl) r ); 64 RationalImpl denominator( Rational(RationalImpl) r ); 65 [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 63 66 64 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 65 void ?{}( Rational(RationalImpl) & r, zero_t ); 67 // numerator/denominator setter 66 68 67 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 68 void ?{}( Rational(RationalImpl) & r, one_t);69 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ); 70 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ); 69 71 70 // numerator/denominator getter 72 // comparison 71 73 72 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 73 RationalImpl numerator( Rational(RationalImpl) r ); 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 ); 74 80 75 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 76 RationalImpl denominator( Rational(RationalImpl) r ); 81 // arithmetic 77 82 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 79 [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 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 ); 80 89 81 // numerator/denominator setter 90 // I/O 91 forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } ) 92 istype & ?|?( istype &, Rational(RationalImpl) & ); 82 93 83 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 84 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ); 85 86 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 87 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ); 88 89 // comparison 90 91 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 92 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 93 94 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 95 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 96 97 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 98 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 99 100 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 101 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 102 103 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 104 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 105 106 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 107 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 108 109 // arithmetic 110 111 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 112 Rational(RationalImpl) +?( Rational(RationalImpl) r ); 113 114 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 115 Rational(RationalImpl) -?( Rational(RationalImpl) r ); 116 117 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 118 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 119 120 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 121 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 122 123 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 124 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 125 126 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 127 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 94 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) 95 ostype & ?|?( ostype &, Rational(RationalImpl ) ); 96 } // distribution 128 97 129 98 // conversion … … 133 102 Rational(RationalImpl) narrow( double f, RationalImpl md ); 134 103 135 // I/O136 forall( otype RationalImpl | arithmetic( RationalImpl ) )137 forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )138 istype & ?|?( istype &, Rational(RationalImpl) & );139 140 forall( otype RationalImpl | arithmetic( RationalImpl ) )141 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )142 ostype & ?|?( ostype &, Rational(RationalImpl ) );143 144 104 // Local Variables: // 145 105 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.