- Timestamp:
- May 14, 2017, 6:30:20 PM (8 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, resolv-new, with_gc
- Children:
- a32cfc90
- Parents:
- 4c8f86b3
- Location:
- src/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/tests/.expect/rational.txt ¶
r4c8f86b3 r561f730 17 17 3/1 18 18 4/3 19 conversion20 0.7521 0.14285714285714322 3.1415929203539823 3/424 1/725 355/11326 19 decompose 27 20 more tests -
TabularUnified src/tests/rational.c ¶
r4c8f86b3 r561f730 10 10 // Created On : Mon Mar 28 08:43:12 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 2 22:11:05201713 // Update Count : 4112 // Last Modified On : Sun May 14 18:10:28 2017 13 // Update Count : 57 14 14 // 15 15 16 #include <rational> 16 17 #include <limits> 17 #include < rational>18 #include <stdlib> 18 19 #include <fstream> 20 21 // UNNECESSARY, FIX ME 22 void ?{}( int * this ) { *this = 0; } 23 void ?{}( int * this, zero_t ) { *this = 0; } 24 void ?{}( int * this, one_t ) { *this = 1; } 19 25 20 26 int main() { 21 27 sout | "constructor" | endl; 22 Rational a = { 3 }, b = { 4 }, c;28 Rational(int) a = { 3 }, b = { 4 }, c; 23 29 sout | a | b | c | endl; 24 a = (Rational){ 4, 8 }; 25 b = (Rational){ 5, 7 }; 30 31 a = (Rational(int)){ 4, 8 }; 32 b = (Rational(int)){ 5, 7 }; 26 33 sout | a | b | endl; 27 a = (Rational ){ -2, -3 };28 b = (Rational ){ 3, -2 };34 a = (Rational(int)){ -2, -3 }; 35 b = (Rational(int)){ 3, -2 }; 29 36 sout | a | b | endl; 30 a = (Rational ){ -2, 3 };31 b = (Rational ){ 3, 2 };37 a = (Rational(int)){ -2, 3 }; 38 b = (Rational(int)){ 3, 2 }; 32 39 sout | a | b | endl; 33 40 34 41 sout | "logical" | endl; 35 a = (Rational ){ -2 };36 b = (Rational ){ -3, 2 };42 a = (Rational(int)){ -2 }; 43 b = (Rational(int)){ -3, 2 }; 37 44 sout | a | b | endl; 38 45 // sout | a == 1 | endl; // FIX ME … … 50 57 sout | a / b | endl; 51 58 52 sout | "conversion" | endl;53 a = (Rational){ 3, 4 };54 sout | widen( a ) | endl;55 a = (Rational){ 1, 7 };56 sout | widen( a ) | endl;57 a = (Rational){ 355, 113 };58 sout | widen( a ) | endl;59 sout | narrow( 0.75, 4 ) | endl;60 sout | narrow( 0.14285714285714, 16 ) | endl;61 sout | narrow( 3.14159265358979, 256 ) | endl;59 // sout | "conversion" | endl; 60 // a = (Rational(int)){ 3, 4 }; 61 // sout | widen( a ) | endl; 62 // a = (Rational(int)){ 1, 7 }; 63 // sout | widen( a ) | endl; 64 // a = (Rational(int)){ 355, 113 }; 65 // sout | widen( a ) | endl; 66 // sout | narrow( 0.75, 4 ) | endl; 67 // sout | narrow( 0.14285714285714, 16 ) | endl; 68 // sout | narrow( 3.14159265358979, 256 ) | endl; 62 69 63 70 sout | "decompose" | endl; 64 RationalImpln, d;71 int n, d; 65 72 // [n, d] = a; 66 73 // sout | a | n | d | endl; 67 74 68 75 sout | "more tests" | endl; 69 Rational x = { 1, 2 }, y = { 2 };76 Rational(int) x = { 1, 2 }, y = { 2 }; 70 77 sout | x - y | endl; 71 78 sout | x > y | endl; … … 73 80 sout | y | denominator( y, -2 ) | y | endl; 74 81 75 Rational z = { 0, 5 };82 Rational(int) z = { 0, 5 }; 76 83 sout | z | endl; 77 84 78 85 sout | x | numerator( x, 0 ) | x | endl; 79 86 80 x = (Rational ){ 1, MAX } + (Rational){ 1, MAX };87 x = (Rational(int)){ 1, MAX } + (Rational(int)){ 1, MAX }; 81 88 sout | x | endl; 82 x = (Rational ){ 3, MAX } + (Rational){ 2, MAX };89 x = (Rational(int)){ 3, MAX } + (Rational(int)){ 2, MAX }; 83 90 sout | x | endl; 84 91
Note: See TracChangeset
for help on using the changeset viewer.