[73abe95] | 1 | // |
---|
[4c8f86b3] | 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. |
---|
[73abe95] | 6 | // |
---|
| 7 | // gmp.c -- |
---|
| 8 | // |
---|
[4c8f86b3] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Tue Apr 19 08:55:51 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[ae4af81] | 12 | // Last Modified On : Sat Aug 18 12:43:13 2018 |
---|
| 13 | // Update Count : 556 |
---|
[73abe95] | 14 | // |
---|
[4c8f86b3] | 15 | |
---|
[c04531fc] | 16 | // NOTE: UBUNTU DOES NOT SUPPORT GMP MULTILIB, SO ONLY 64-BIT GMP IS TESTED. |
---|
| 17 | |
---|
[73abe95] | 18 | #include <gmp.hfa> |
---|
[4c8f86b3] | 19 | |
---|
[935315d] | 20 | int main( void ) { |
---|
[4c8f86b3] | 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; |
---|
[4adbe45] | 30 | y = "12345678901234567890123456789"; |
---|
| 31 | sout | "y:" | y | endl; |
---|
[3f8dd01] | 32 | y = 100`mp + 100`mp; |
---|
| 33 | sout | "y:" | y | endl; |
---|
| 34 | y = -200u`mp + -200u`mp; |
---|
| 35 | sout | "y:" | y | endl; |
---|
| 36 | y = "12345678901234567890123456789"`mp + "12345678901234567890123456789"`mp; |
---|
| 37 | sout | "y:" | y | endl; |
---|
[4c8f86b3] | 38 | y = si; |
---|
| 39 | sout | "y:" | y | endl; |
---|
| 40 | y = -3; |
---|
| 41 | sout | "y:" | y | endl; |
---|
| 42 | y += 7; |
---|
| 43 | sout | "y:" | y | endl; |
---|
| 44 | y -= 1; |
---|
| 45 | sout | "y:" | y | endl; |
---|
| 46 | int b; |
---|
| 47 | b = y; |
---|
| 48 | si = y; |
---|
| 49 | sout | "y:" | y | "b:" | b | "si:" | si | endl; |
---|
| 50 | |
---|
| 51 | sout | "comparison" | endl; |
---|
| 52 | sout | x == x | endl; |
---|
| 53 | sout | x != x | endl; |
---|
| 54 | sout | x < x | endl; |
---|
| 55 | sout | x <= x | endl; |
---|
| 56 | sout | x > x | endl; |
---|
| 57 | sout | x >= x | endl; |
---|
| 58 | |
---|
| 59 | sout | "arithmetic" | endl; |
---|
| 60 | z = x + y + z; |
---|
| 61 | sout | "z:" | z | endl; |
---|
| 62 | z = z = x; |
---|
| 63 | sout | "z:" | z | endl; |
---|
| 64 | z = x - y - z; |
---|
| 65 | sout | "z:" | z | endl; |
---|
| 66 | z = x * y * z; |
---|
| 67 | sout | "z:" | z | endl; |
---|
| 68 | z = x * 3; |
---|
| 69 | sout | "z:" | z | endl; |
---|
| 70 | z = 3 * x; |
---|
| 71 | sout | "z:" | z | endl; |
---|
| 72 | z = x / 3; |
---|
| 73 | sout | "z:" | z | endl; |
---|
[4adbe45] | 74 | sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl; |
---|
[4c8f86b3] | 75 | [ x, y ] = div( x, 3 ); |
---|
| 76 | sout | "x:" | x | "y:" | y | endl; |
---|
| 77 | |
---|
| 78 | sout | endl; |
---|
| 79 | |
---|
[1ae39f6e] | 80 | sin | x | y | z; |
---|
| 81 | sout | x | y | z | endl; |
---|
| 82 | |
---|
| 83 | sout | endl; |
---|
| 84 | |
---|
[4c8f86b3] | 85 | sout | "Fibonacci Numbers" | endl; |
---|
| 86 | Int fn, fn1, fn2; |
---|
| 87 | fn = (Int){0}; fn1 = fn; // 1st case |
---|
| 88 | sout | (int)0 | fn | endl; |
---|
[18c55e1] | 89 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case |
---|
[4c8f86b3] | 90 | sout | 1 | fn | endl; |
---|
[ae4af81] | 91 | for ( i; 2u ~= 200 ) { |
---|
[4c8f86b3] | 92 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
---|
| 93 | sout | i | fn | endl; |
---|
| 94 | } // for |
---|
| 95 | |
---|
| 96 | sout | endl; |
---|
| 97 | |
---|
| 98 | sout | "Factorial Numbers" | endl; |
---|
[f802e46] | 99 | Int fact = 1; // 1st case |
---|
[4c8f86b3] | 100 | sout | (int)0 | fact | endl; |
---|
[ae4af81] | 101 | for ( i; 1u ~= 40u ) { |
---|
[a933bcb3] | 102 | fact *= i; // general case |
---|
[4c8f86b3] | 103 | sout | i | fact | endl; |
---|
| 104 | } // for |
---|
| 105 | } // main |
---|
| 106 | |
---|
| 107 | // Local Variables: // |
---|
| 108 | // tab-width: 4 // |
---|
[933dbbd] | 109 | // compile-command: "cfa gmp.c -lgmp" // |
---|
[4c8f86b3] | 110 | // End: // |
---|