source: src/tests/rational.c @ cc640aad

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 cc640aad was a6151ba, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

update comments in code and tests, and add test searchsort

  • Property mode set to 100644
File size: 2.0 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
[a6151ba]12// Last Modified On : Tue Jul  5 18:29:37 2016
13// Update Count     : 25
[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;
38        sout | a == 1 | endl;
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
[d1ab5331]63        Rational x = { 1, 2 }, y = { 2 };
[53ba273]64        sout | x - y | endl;
65        sout | x > y | endl;
66        sout | x | numerator( x, 2 ) | x | endl;
67        sout | y | denominator( y, -2 ) | y | endl;
68
[d1ab5331]69        Rational z = { 0, 5 };
[53ba273]70        sout | z | endl;
71
72        sout | x | numerator( x, 0 ) | x | endl;
73
[d1ab5331]74        x = (Rational){ 1, MAX } + (Rational){ 1, MAX };
[53ba273]75        sout | x | endl;
[d1ab5331]76        x = (Rational){ 3, MAX } + (Rational){ 2, MAX };
[53ba273]77        sout | x | endl;
78
79        sin | &a | &b;
80        sout | a | b | endl;
81} // main
82
83// Local Variables: //
84// tab-width: 4 //
85// compile-command: "cfa rational.c" //
86// End: //
Note: See TracBrowser for help on using the repository browser.