aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change
on this file since 53ba273 was
53ba273,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
switch from std=c99 to std=gnu99, update latex macros, refrat and extend user manual, update limits/iostream/fstream, add rational numbers
|
-
Property mode set to
100644
|
File size:
2.1 KB
|
Line | |
---|
1 | // -*- Mode: C -*- |
---|
2 | // |
---|
3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
4 | // |
---|
5 | // The contents of this file are covered under the licence agreement in the |
---|
6 | // file "LICENCE" distributed with Cforall. |
---|
7 | // |
---|
8 | // rational.c -- |
---|
9 | // |
---|
10 | // Author : Peter A. Buhr |
---|
11 | // Created On : Mon Mar 28 08:43:12 2016 |
---|
12 | // Last Modified By : Peter A. Buhr |
---|
13 | // Last Modified On : Wed Apr 6 18:02:02 2016 |
---|
14 | // Update Count : 19 |
---|
15 | // |
---|
16 | |
---|
17 | #include <limits> |
---|
18 | #include <rational> |
---|
19 | |
---|
20 | int main() { |
---|
21 | Rational a, b, c; |
---|
22 | sout | "constructor" | endl; |
---|
23 | a = rational( 3 ); |
---|
24 | b = rational( 4 ); |
---|
25 | c = rational(); |
---|
26 | sout | a | b | c | endl; |
---|
27 | a = rational( 4, 8 ); |
---|
28 | b = rational( 5, 7 ); |
---|
29 | sout | a | b | endl; |
---|
30 | a = rational( -2, -3 ); |
---|
31 | b = rational( 3, -2 ); |
---|
32 | sout | a | b | endl; |
---|
33 | a = rational( -2, 3 ); |
---|
34 | b = rational( 3, 2 ); |
---|
35 | sout | a | b | endl; |
---|
36 | |
---|
37 | sout | "logical" | endl; |
---|
38 | a = rational( -2 ); |
---|
39 | b = rational( -3, 2 ); |
---|
40 | sout | a | b | endl; |
---|
41 | sout | a == 1 | endl; |
---|
42 | sout | a != b | endl; |
---|
43 | sout | a < b | endl; |
---|
44 | sout | a <= b | endl; |
---|
45 | sout | a > b | endl; |
---|
46 | sout | a >= b | endl; |
---|
47 | |
---|
48 | sout | "arithmetic" | endl; |
---|
49 | sout | a | b | endl; |
---|
50 | sout | a + b | endl; |
---|
51 | sout | a - b | endl; |
---|
52 | sout | a * b | endl; |
---|
53 | sout | a / b | endl; |
---|
54 | |
---|
55 | sout | "conversion" | endl; |
---|
56 | a = rational( 3, 4 ); |
---|
57 | sout | widen( a ) | endl; |
---|
58 | a = rational( 1, 7 ); |
---|
59 | sout | widen( a ) | endl; |
---|
60 | a = rational( 355, 113 ); |
---|
61 | sout | widen( a ) | endl; |
---|
62 | sout | narrow( 0.75, 4 ) | endl; |
---|
63 | sout | narrow( 0.14285714285714, 16 ) | endl; |
---|
64 | sout | narrow( 3.14159265358979, 256 ) | endl; |
---|
65 | |
---|
66 | Rational x, y; |
---|
67 | x = rational( 1, 2 ); |
---|
68 | y = rational( 2 ); |
---|
69 | sout | x - y | endl; |
---|
70 | sout | x > y | endl; |
---|
71 | sout | x | numerator( x, 2 ) | x | endl; |
---|
72 | sout | y | denominator( y, -2 ) | y | endl; |
---|
73 | |
---|
74 | Rational z; |
---|
75 | z = rational( 0, 5 ); |
---|
76 | sout | z | endl; |
---|
77 | |
---|
78 | sout | x | numerator( x, 0 ) | x | endl; |
---|
79 | |
---|
80 | x = rational( 1, MAX ) + rational( 1, MAX ); |
---|
81 | sout | x | endl; |
---|
82 | x = rational( 3, MAX ) + rational( 2, MAX ); |
---|
83 | sout | x | endl; |
---|
84 | |
---|
85 | sin | &a | &b; |
---|
86 | sout | a | b | endl; |
---|
87 | } // main |
---|
88 | |
---|
89 | // Local Variables: // |
---|
90 | // tab-width: 4 // |
---|
91 | // compile-command: "cfa rational.c" // |
---|
92 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.