source: src/tests/gmp.c @ 0b150ec

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 0b150ec was 4c8f86b3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add gmp interface and test

  • 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// 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 : Sun May 14 14:46:50 2017
13// Update Count     : 530
14//
15
16#include <gmp>
17
18int main() {
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 = si;
29        sout | "y:" | y | endl;
30        y = -3;
31        sout | "y:" | y | endl;
32        y += 7;
33        sout | "y:" | y | endl;
34        y -= 1;
35        sout | "y:" | y | endl;
36        int b;
37        b = y;
38        si = y;
39        sout | "y:" | y | "b:" | b | "si:" | si | endl;
40
41        sout | "comparison" | endl;
42        sout | x == x | endl;
43        sout | x != x | endl;
44        sout | x < x | endl;
45        sout | x <= x | endl;
46        sout | x > x | endl;
47        sout | x >= x | endl;
48
49        sout | "arithmetic" | endl;
50        z = x + y + z;
51        sout | "z:" | z | endl;
52        z = z = x;
53        sout | "z:" | z | endl;
54        z = x - y - z;
55        sout | "z:" | z | endl;
56        z = x * y * z;
57        sout | "z:" | z | endl;
58        z = x * 3;
59        sout | "z:" | z | endl;
60        z = 3 * x;
61        sout | "z:" | z | endl;
62        z = x / 3;
63        sout | "z:" | z | endl;
64        [ x, y ] = div( x, 3 );
65        sout | "x:" | x | "y:" | y | endl;
66//      sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
67
68        sout | endl;
69
70        sout | "Fibonacci Numbers" | endl;
71        Int fn, fn1, fn2;
72        fn = (Int){0}; fn1 = fn;                                                        // 1st case
73        sout | (int)0 | fn | endl;
74        fn = (Int){1}; fn2 = fn1; fn1 = fn;                                     // 2nd case
75        sout | 1 | fn | endl;
76        for ( int i = 2; i <= 200; i += 1 ) {
77                fn = fn1 + fn2; fn2 = fn1; fn1 = fn;                    // general case
78                sout | i | fn | endl;
79        } // for
80
81        sout | endl;
82
83        sout | "Factorial Numbers" | endl;
84        Int fact;
85        fact = (Int){1};                                                                        // 1st case
86        sout | (int)0 | fact | endl;
87        for ( int i = 1; i <= 40; i += 1 ) {
88                fact = fact * i;                                                                // general case
89                sout | i | fact | endl;
90        } // for
91} // main
92
93// Local Variables: //
94// mode: c //
95// tab-width: 4 //
96// End: //
Note: See TracBrowser for help on using the repository browser.