source: src/tests/gmp.c @ 935315d

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

use unsigned int for loop index

  • Property mode set to 100644
File size: 2.2 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// gmp.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Tue Apr 19 08:55:51 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon May 22 09:05:09 2017
13// Update Count     : 538
14//
15
16#include <gmp>
17
18int main( void ) {
19        sout | "constructors" | endl;
20        short int si = 3;
21        Int x = { "50000000000000000000" }, y = { si }, z = x + y;
22        sout | x | y | z | endl;
23        sout | "x:" | x | "y:" | y | "z:" | z | endl;
24
25        sout | "conversions" | endl;
26        y = 'a';
27        sout | "y:" | y | endl;
28        y = "12345678901234567890123456789";
29        sout | "y:" | y | endl;
30        y = si;
31        sout | "y:" | y | endl;
32        y = -3;
33        sout | "y:" | y | endl;
34        y += 7;
35        sout | "y:" | y | endl;
36        y -= 1;
37        sout | "y:" | y | endl;
38        int b;
39        b = y;
40        si = y;
41        sout | "y:" | y | "b:" | b | "si:" | si | endl;
42
43        sout | "comparison" | endl;
44        sout | x == x | endl;
45        sout | x != x | endl;
46        sout | x < x | endl;
47        sout | x <= x | endl;
48        sout | x > x | endl;
49        sout | x >= x | endl;
50
51        sout | "arithmetic" | endl;
52        z = x + y + z;
53        sout | "z:" | z | endl;
54        z = z = x;
55        sout | "z:" | z | endl;
56        z = x - y - z;
57        sout | "z:" | z | endl;
58        z = x * y * z;
59        sout | "z:" | z | endl;
60        z = x * 3;
61        sout | "z:" | z | endl;
62        z = 3 * x;
63        sout | "z:" | z | endl;
64        z = x / 3;
65        sout | "z:" | z | endl;
66        sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
67        [ x, y ] = div( x, 3 );
68        sout | "x:" | x | "y:" | y | endl;
69
70        sout | endl;
71
72        sout | "Fibonacci Numbers" | endl;
73        Int fn, fn1, fn2;
74        fn = (Int){0}; fn1 = fn;                                                        // 1st case
75        sout | (int)0 | fn | endl;
76        fn = 1; fn2 = fn1; fn1 = fn;                                            // 2nd case
77        sout | 1 | fn | endl;
78        for ( unsigned int i = 2; i <= 200; i += 1 ) {
79                fn = fn1 + fn2; fn2 = fn1; fn1 = fn;                    // general case
80                sout | i | fn | endl;
81        } // for
82
83        sout | endl;
84
85        sout | "Factorial Numbers" | endl;
86        Int fact;
87        fact = 1;                                                                                       // 1st case
88        sout | (int)0 | fact | endl;
89        for ( unsigned int i = 1; i <= 40; i += 1 ) {
90                fact = fact * i;                                                                // general case
91                sout | i | fact | endl;
92        } // for
93} // main
94
95// Local Variables: //
96// mode: c //
97// tab-width: 4 //
98// End: //
Note: See TracBrowser for help on using the repository browser.