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 : Fri Aug 25 12:50:01 2017 |
---|
13 | // Update Count : 544 |
---|
14 | // |
---|
15 | |
---|
16 | // NOTE: UBUNTU DOES NOT SUPPORT GMP MULTILIB, SO ONLY 64-BIT GMP IS TESTED. |
---|
17 | |
---|
18 | #include <gmp> |
---|
19 | |
---|
20 | int main( void ) { |
---|
21 | sout | "constructors" | endl; |
---|
22 | short int si = 3; |
---|
23 | Int x = { "50000000000000000000" }, y = { si }, z = x + y; |
---|
24 | sout | x | y | z | endl; |
---|
25 | sout | "x:" | x | "y:" | y | "z:" | z | endl; |
---|
26 | |
---|
27 | sout | "conversions" | endl; |
---|
28 | y = 'a'; |
---|
29 | sout | "y:" | y | endl; |
---|
30 | y = "12345678901234567890123456789"; |
---|
31 | sout | "y:" | y | endl; |
---|
32 | y = si; |
---|
33 | sout | "y:" | y | endl; |
---|
34 | y = -3; |
---|
35 | sout | "y:" | y | endl; |
---|
36 | y += 7; |
---|
37 | sout | "y:" | y | endl; |
---|
38 | y -= 1; |
---|
39 | sout | "y:" | y | endl; |
---|
40 | int b; |
---|
41 | b = y; |
---|
42 | si = y; |
---|
43 | sout | "y:" | y | "b:" | b | "si:" | si | endl; |
---|
44 | |
---|
45 | sout | "comparison" | endl; |
---|
46 | sout | x == x | endl; |
---|
47 | sout | x != x | endl; |
---|
48 | sout | x < x | endl; |
---|
49 | sout | x <= x | endl; |
---|
50 | sout | x > x | endl; |
---|
51 | sout | x >= x | endl; |
---|
52 | |
---|
53 | sout | "arithmetic" | endl; |
---|
54 | z = x + y + z; |
---|
55 | sout | "z:" | z | endl; |
---|
56 | z = z = x; |
---|
57 | sout | "z:" | z | endl; |
---|
58 | z = x - y - z; |
---|
59 | sout | "z:" | z | endl; |
---|
60 | z = x * y * z; |
---|
61 | sout | "z:" | z | endl; |
---|
62 | z = x * 3; |
---|
63 | sout | "z:" | z | endl; |
---|
64 | z = 3 * x; |
---|
65 | sout | "z:" | z | endl; |
---|
66 | z = x / 3; |
---|
67 | sout | "z:" | z | endl; |
---|
68 | sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl; |
---|
69 | [ x, y ] = div( x, 3 ); |
---|
70 | sout | "x:" | x | "y:" | y | endl; |
---|
71 | |
---|
72 | sout | endl; |
---|
73 | |
---|
74 | sin | x | y | z; |
---|
75 | sout | x | y | z | endl; |
---|
76 | |
---|
77 | sout | endl; |
---|
78 | |
---|
79 | sout | "Fibonacci Numbers" | endl; |
---|
80 | Int fn, fn1, fn2; |
---|
81 | fn = (Int){0}; fn1 = fn; // 1st case |
---|
82 | sout | (int)0 | fn | endl; |
---|
83 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case |
---|
84 | sout | 1 | fn | endl; |
---|
85 | for ( unsigned int i = 2; i <= 200; i += 1 ) { |
---|
86 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
---|
87 | sout | i | fn | endl; |
---|
88 | } // for |
---|
89 | |
---|
90 | sout | endl; |
---|
91 | |
---|
92 | sout | "Factorial Numbers" | endl; |
---|
93 | Int fact; |
---|
94 | fact = 1; // 1st case |
---|
95 | sout | (int)0 | fact | endl; |
---|
96 | for ( unsigned int i = 1; i <= 40; i += 1 ) { |
---|
97 | fact *= i; // general case |
---|
98 | sout | i | fact | endl; |
---|
99 | } // for |
---|
100 | } // main |
---|
101 | |
---|
102 | // Local Variables: // |
---|
103 | // tab-width: 4 // |
---|
104 | // compile-command: "cfa gmp.c -lgmp" // |
---|
105 | // End: // |
---|