ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
ctor
deferred_resn
demangler
enum
forall-pointer-decay
gc_noraii
jacob/cs343-translation
jenkins-sandbox
memory
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
string
with_gc
Last change
on this file since 37f0da8 was 630a82a, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago |
C99 compound literals now work, comment rational code, clean up hoisting AddVisit
|
-
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 -- test rational number package
|
---|
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 : Fri Apr 8 11:27:48 2016
|
---|
14 | // Update Count : 21
|
---|
15 | //
|
---|
16 |
|
---|
17 | #include <limits>
|
---|
18 | #include <rational>
|
---|
19 | #include <fstream>
|
---|
20 |
|
---|
21 | int main() {
|
---|
22 | Rational a, b, c;
|
---|
23 | sout | "constructor" | endl;
|
---|
24 | a = rational( 3 );
|
---|
25 | b = rational( 4 );
|
---|
26 | c = rational();
|
---|
27 | sout | a | b | c | endl;
|
---|
28 | a = rational( 4, 8 );
|
---|
29 | b = rational( 5, 7 );
|
---|
30 | sout | a | b | endl;
|
---|
31 | a = rational( -2, -3 );
|
---|
32 | b = rational( 3, -2 );
|
---|
33 | sout | a | b | endl;
|
---|
34 | a = rational( -2, 3 );
|
---|
35 | b = rational( 3, 2 );
|
---|
36 | sout | a | b | endl;
|
---|
37 |
|
---|
38 | sout | "logical" | endl;
|
---|
39 | a = rational( -2 );
|
---|
40 | b = rational( -3, 2 );
|
---|
41 | sout | a | b | endl;
|
---|
42 | sout | a == 1 | endl;
|
---|
43 | sout | a != b | endl;
|
---|
44 | sout | a < b | endl;
|
---|
45 | sout | a <= b | endl;
|
---|
46 | sout | a > b | endl;
|
---|
47 | sout | a >= b | endl;
|
---|
48 |
|
---|
49 | sout | "arithmetic" | endl;
|
---|
50 | sout | a | b | endl;
|
---|
51 | sout | a + b | endl;
|
---|
52 | sout | a - b | endl;
|
---|
53 | sout | a * b | endl;
|
---|
54 | sout | a / b | endl;
|
---|
55 |
|
---|
56 | sout | "conversion" | endl;
|
---|
57 | a = rational( 3, 4 );
|
---|
58 | sout | widen( a ) | endl;
|
---|
59 | a = rational( 1, 7 );
|
---|
60 | sout | widen( a ) | endl;
|
---|
61 | a = rational( 355, 113 );
|
---|
62 | sout | widen( a ) | endl;
|
---|
63 | sout | narrow( 0.75, 4 ) | endl;
|
---|
64 | sout | narrow( 0.14285714285714, 16 ) | endl;
|
---|
65 | sout | narrow( 3.14159265358979, 256 ) | endl;
|
---|
66 |
|
---|
67 | Rational x, y;
|
---|
68 | x = rational( 1, 2 );
|
---|
69 | y = rational( 2 );
|
---|
70 | sout | x - y | endl;
|
---|
71 | sout | x > y | endl;
|
---|
72 | sout | x | numerator( x, 2 ) | x | endl;
|
---|
73 | sout | y | denominator( y, -2 ) | y | endl;
|
---|
74 |
|
---|
75 | Rational z;
|
---|
76 | z = rational( 0, 5 );
|
---|
77 | sout | z | endl;
|
---|
78 |
|
---|
79 | sout | x | numerator( x, 0 ) | x | endl;
|
---|
80 |
|
---|
81 | x = rational( 1, MAX ) + rational( 1, MAX );
|
---|
82 | sout | x | endl;
|
---|
83 | x = rational( 3, MAX ) + rational( 2, MAX );
|
---|
84 | sout | x | endl;
|
---|
85 |
|
---|
86 | sin | &a | &b;
|
---|
87 | sout | a | b | endl;
|
---|
88 | } // main
|
---|
89 |
|
---|
90 | // Local Variables: //
|
---|
91 | // tab-width: 4 //
|
---|
92 | // compile-command: "cfa rational.c" //
|
---|
93 | // End: //
|
---|
Note:
See
TracBrowser
for help on using the repository browser.