Changeset f00b2c2c
- Timestamp:
- Feb 9, 2020, 8:56:01 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d231700
- Parents:
- 8c9da33
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/rational.cfa
r8c9da33 rf00b2c2c 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 12 18:12:08 201913 // Update Count : 18 412 // Last Modified On : Sat Feb 8 17:56:36 2020 13 // Update Count : 187 14 14 // 15 15 … … 56 56 } // rational 57 57 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 58 65 59 66 // getter for numerator/denominator -
tests/.expect/rational.txt
r8c9da33 rf00b2c2c 1 1 constructor 2 3/1 4/1 0/1 2 3/1 4/1 0/1 0/1 1/1 3 3 1/2 5/7 4 4 2/3 -3/2 -
tests/rational.cfa
r8c9da33 rf00b2c2c 10 10 // Created On : Mon Mar 28 08:43:12 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 27 07:37:17 201913 // Update Count : 8 012 // Last Modified On : Sat Feb 8 18:46:23 2020 13 // Update Count : 86 14 14 // 15 15 … … 19 19 #include <fstream.hfa> 20 20 21 double convert( int i ) { return (double)i; } 21 typedef Rational(int) RatInt; 22 double convert( int i ) { return (double)i; } // used by narrow/widen 22 23 int convert( double d ) { return (int)d; } 23 24 24 25 int main() { 25 26 sout | "constructor"; 26 Rat ional(int) a = { 3 }, b = { 4 }, c;27 sout | a | b | c ;27 RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1; 28 sout | a | b | c | d | e; 28 29 29 a = (Rat ional(int)){ 4, 8 };30 b = (Rat ional(int)){ 5, 7 };30 a = (RatInt){ 4, 8 }; 31 b = (RatInt){ 5, 7 }; 31 32 sout | a | b; 32 a = (Rat ional(int)){ -2, -3 };33 b = (Rat ional(int)){ 3, -2 };33 a = (RatInt){ -2, -3 }; 34 b = (RatInt){ 3, -2 }; 34 35 sout | a | b; 35 a = (Rat ional(int)){ -2, 3 };36 b = (Rat ional(int)){ 3, 2 };36 a = (RatInt){ -2, 3 }; 37 b = (RatInt){ 3, 2 }; 37 38 sout | a | b; 38 39 39 40 sout | "logical"; 40 a = (Rat ional(int)){ -2 };41 b = (Rat ional(int)){ -3, 2 };41 a = (RatInt){ -2 }; 42 b = (RatInt){ -3, 2 }; 42 43 sout | a | b; 43 44 // sout | a == 1; // FIX ME … … 58 59 59 60 sout | "conversion"; 60 a = (Rat ional(int)){ 3, 4 };61 a = (RatInt){ 3, 4 }; 61 62 sout | widen( a ); 62 a = (Rat ional(int)){ 1, 7 };63 a = (RatInt){ 1, 7 }; 63 64 sout | widen( a ); 64 a = (Rat ional(int)){ 355, 113 };65 a = (RatInt){ 355, 113 }; 65 66 sout | widen( a ); 66 67 sout | narrow( 0.75, 4 ); … … 74 75 75 76 sout | "more tests"; 76 Rat ional(int)x = { 1, 2 }, y = { 2 };77 RatInt x = { 1, 2 }, y = { 2 }; 77 78 sout | x - y; 78 79 sout | x > y; … … 80 81 sout | y | denominator( y, -2 ) | y; 81 82 82 Rat ional(int)z = { 0, 5 };83 RatInt z = { 0, 5 }; 83 84 sout | z; 84 85 85 86 sout | x | numerator( x, 0 ) | x; 86 87 87 x = (Rat ional(int)){ 1, MAX } + (Rational(int)){ 1, MAX };88 x = (RatInt){ 1, MAX } + (RatInt){ 1, MAX }; 88 89 sout | x; 89 x = (Rat ional(int)){ 3, MAX } + (Rational(int)){ 2, MAX };90 x = (RatInt){ 3, MAX } + (RatInt){ 2, MAX }; 90 91 sout | x; 91 92
Note: See TracChangeset
for help on using the changeset viewer.