source: src/tests/rational.c @ f621a148

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since f621a148 was f621a148, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

change to implementation type for rational and add to test suite

  • Property mode set to 100644
File size: 2.1 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.c -- 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 : Thu Apr 27 17:05:19 2017
13// Update Count     : 40
14//
15
16#include <limits>
17#include <rational>
18#include <fstream>
19
20int main() {
21        sout | "constructor" | endl;
22        Rational a = { 3 }, b = { 4 }, c;
23        sout | a | b | c | endl;
24        a = (Rational){ 4, 8 };
25        b = (Rational){ 5, 7 };
26        sout | a | b | endl;
27        a = (Rational){ -2, -3 };
28        b = (Rational){ 3, -2 };
29        sout | a | b | endl;
30        a = (Rational){ -2, 3 };
31        b = (Rational){ 3, 2 };
32        sout | a | b | endl;
33
34        sout | "logical" | endl;
35        a = (Rational){ -2 };
36        b = (Rational){ -3, 2 };
37        sout | a | b | endl;
38//      sout | a == 1 | endl; // FIX ME
39        sout | a != b | endl;
40        sout | a <  b | endl;
41        sout | a <= b | endl;
42        sout | a >  b | endl;
43        sout | a >= b | endl;
44
45        sout | "arithmetic" | endl;
46        sout | a | b | endl;
47        sout | a + b | endl;
48        sout | a - b | endl;
49        sout | a * b | endl;
50        sout | a / b | endl;
51
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;
62
63        sout | "decompose" | endl;
64        RationalImpl n, d;
65        [n, d] = a;
66        sout | a | n | d | endl;
67
68        sout | "more tests" | endl;
69        Rational x = { 1, 2 }, y = { 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 = { 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.