source: src/tests/rational.c @ 66ef082

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 66ef082 was 39c5ea3, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

fix rational failure

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[53ba273]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//
[630a82a]7// rational.c -- test rational number package
[53ba273]8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Mar 28 08:43:12 2016
11// Last Modified By : Peter A. Buhr
[39c5ea3]12// Last Modified On : Tue May  2 22:11:05 2017
13// Update Count     : 41
[53ba273]14//
15
16#include <limits>
17#include <rational>
[3d9b5da]18#include <fstream>
[53ba273]19
20int main() {
21        sout | "constructor" | endl;
[d1ab5331]22        Rational a = { 3 }, b = { 4 }, c;
[53ba273]23        sout | a | b | c | endl;
[d1ab5331]24        a = (Rational){ 4, 8 };
25        b = (Rational){ 5, 7 };
[53ba273]26        sout | a | b | endl;
[d1ab5331]27        a = (Rational){ -2, -3 };
28        b = (Rational){ 3, -2 };
[53ba273]29        sout | a | b | endl;
[d1ab5331]30        a = (Rational){ -2, 3 };
31        b = (Rational){ 3, 2 };
[53ba273]32        sout | a | b | endl;
33
34        sout | "logical" | endl;
[d1ab5331]35        a = (Rational){ -2 };
36        b = (Rational){ -3, 2 };
[53ba273]37        sout | a | b | endl;
[f621a148]38//      sout | a == 1 | endl; // FIX ME
[53ba273]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;
[d1ab5331]53        a = (Rational){ 3, 4 };
[53ba273]54        sout | widen( a ) | endl;
[d1ab5331]55        a = (Rational){ 1, 7 };
[53ba273]56        sout | widen( a ) | endl;
[d1ab5331]57        a = (Rational){ 355, 113 };
[53ba273]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
[f621a148]63        sout | "decompose" | endl;
64        RationalImpl n, d;
[39c5ea3]65//      [n, d] = a;
66//      sout | a | n | d | endl;
[f621a148]67
68        sout | "more tests" | endl;
[d1ab5331]69        Rational x = { 1, 2 }, y = { 2 };
[53ba273]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
[d1ab5331]75        Rational z = { 0, 5 };
[53ba273]76        sout | z | endl;
77
78        sout | x | numerator( x, 0 ) | x | endl;
79
[d1ab5331]80        x = (Rational){ 1, MAX } + (Rational){ 1, MAX };
[53ba273]81        sout | x | endl;
[d1ab5331]82        x = (Rational){ 3, MAX } + (Rational){ 2, MAX };
[53ba273]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.