source: src/tests/gmp.c@ e9145a3

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since e9145a3 was 933dbbd, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

fix internal compile command

  • 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 : Thu Jul 13 16:35:01 2017
13// Update Count : 541
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 *= i; // general case
91 sout | i | fact | endl;
92 } // for
93} // main
94
95// Local Variables: //
96// tab-width: 4 //
97// compile-command: "cfa gmp.c -lgmp" //
98// End: //
Note: See TracBrowser for help on using the repository browser.