source: tests/rational.cfa @ 200fcb3

aaron-thesisarm-ehcleanup-dtorsdeferred_resnjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexer
Last change on this file since 200fcb3 was 200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

add auto newline to sout, change endl to nl

  • Property mode set to 100644
File size: 2.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// rational.cfa -- test rational number package
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Mar 28 08:43:12 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Dec  4 21:46:42 2018
13// Update Count     : 69
14//
15
16#include <rational.hfa>
17#include <limits.hfa>
18#include <stdlib.hfa>
19#include <fstream.hfa>
20
21// UNNECESSARY, FIX ME
22void ?{}( int & this ) { this = 0; }
23void ?{}( int & this, zero_t ) { this = 0; }
24void ?{}( int & this, one_t ) { this = 1; }
25double convert( int i ) { return (double)i; }
26int convert( double d ) { return (int)d; }
27
28int main() {
29        sout | "constructor";
30        Rational(int) a = { 3 }, b = { 4 }, c;
31        sout | a | b | c;
32
33        a = (Rational(int)){ 4, 8 };
34        b = (Rational(int)){ 5, 7 };
35        sout | a | b;
36        a = (Rational(int)){ -2, -3 };
37        b = (Rational(int)){ 3, -2 };
38        sout | a | b;
39        a = (Rational(int)){ -2, 3 };
40        b = (Rational(int)){ 3, 2 };
41        sout | a | b;
42
43        sout | "logical";
44        a = (Rational(int)){ -2 };
45        b = (Rational(int)){ -3, 2 };
46        sout | a | b;
47//      sout | a == 1; // FIX ME
48        sout | a != b;
49        sout | a <  b;
50        sout | a <= b;
51        sout | a >  b;
52        sout | a >= b;
53
54        sout | "arithmetic";
55        sout | a | b;
56        sout | a + b;
57        sout | a - b;
58        sout | a * b;
59        sout | a / b;
60
61        sout | "conversion";
62        a = (Rational(int)){ 3, 4 };
63        sout | widen( a );
64        a = (Rational(int)){ 1, 7 };
65        sout | widen( a );
66        a = (Rational(int)){ 355, 113 };
67        sout | widen( a );
68        sout | narrow( 0.75, 4 );
69        sout | narrow( 0.14285714285714, 16 );
70        sout | narrow( 3.14159265358979, 256 );
71
72        sout | "decompose";
73        int n, d;
74//      [n, d] = a;
75//      sout | a | n | d;
76
77        sout | "more tests";
78        Rational(int) x = { 1, 2 }, y = { 2 };
79        sout | x - y;
80        sout | x > y;
81        sout | x | numerator( x, 2 ) | x;
82        sout | y | denominator( y, -2 ) | y;
83
84        Rational(int) z = { 0, 5 };
85        sout | z;
86
87        sout | x | numerator( x, 0 ) | x;
88
89        x = (Rational(int)){ 1, MAX } + (Rational(int)){ 1, MAX };
90        sout | x;
91        x = (Rational(int)){ 3, MAX } + (Rational(int)){ 2, MAX };
92        sout | x;
93
94        sin | a | b;
95        sout | a | b;
96} // main
97
98// Local Variables: //
99// tab-width: 4 //
100// compile-command: "cfa rational.cfa" //
101// End: //
Note: See TracBrowser for help on using the repository browser.