source:
tests/gmp.cfa
@
075c6d5
Last change on this file since 075c6d5 was 5ea5b28, checked in by , 6 years ago | |
---|---|
|
|
File size: 2.2 KB |
Rev | Line | |
---|---|---|
[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 | // |
[dc8511c] | 7 | // gmp.cfa -- |
[73abe95] | 8 | // |
[4c8f86b3] | 9 | // Author : Peter A. Buhr |
10 | // Created On : Tue Apr 19 08:55:51 2016 | |
11 | // Last Modified By : Peter A. Buhr | |
[5ea5b28] | 12 | // Last Modified On : Thu Dec 20 22:41:47 2018 |
13 | // Update Count : 559 | |
[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 ) { |
[200fcb3] | 21 | sout | "constructors"; |
[4c8f86b3] | 22 | short int si = 3; |
23 | Int x = { "50000000000000000000" }, y = { si }, z = x + y; | |
[200fcb3] | 24 | sout | x | y | z; |
25 | sout | "x:" | x | "y:" | y | "z:" | z; | |
[4c8f86b3] | 26 | |
[200fcb3] | 27 | sout | "conversions"; |
[4c8f86b3] | 28 | y = 'a'; |
[200fcb3] | 29 | sout | "y:" | y; |
[4adbe45] | 30 | y = "12345678901234567890123456789"; |
[200fcb3] | 31 | sout | "y:" | y; |
[3f8dd01] | 32 | y = 100`mp + 100`mp; |
[200fcb3] | 33 | sout | "y:" | y; |
[3f8dd01] | 34 | y = -200u`mp + -200u`mp; |
[200fcb3] | 35 | sout | "y:" | y; |
[3f8dd01] | 36 | y = "12345678901234567890123456789"`mp + "12345678901234567890123456789"`mp; |
[200fcb3] | 37 | sout | "y:" | y; |
[4c8f86b3] | 38 | y = si; |
[200fcb3] | 39 | sout | "y:" | y; |
[4c8f86b3] | 40 | y = -3; |
[200fcb3] | 41 | sout | "y:" | y; |
[4c8f86b3] | 42 | y += 7; |
[200fcb3] | 43 | sout | "y:" | y; |
[4c8f86b3] | 44 | y -= 1; |
[200fcb3] | 45 | sout | "y:" | y; |
[4c8f86b3] | 46 | int b; |
47 | b = y; | |
48 | si = y; | |
[200fcb3] | 49 | sout | "y:" | y | "b:" | b | "si:" | si; |
[4c8f86b3] | 50 | |
[200fcb3] | 51 | sout | "comparison"; |
52 | sout | x == x; | |
53 | sout | x != x; | |
54 | sout | x < x; | |
55 | sout | x <= x; | |
56 | sout | x > x; | |
57 | sout | x >= x; | |
[4c8f86b3] | 58 | |
[200fcb3] | 59 | sout | "arithmetic"; |
[4c8f86b3] | 60 | z = x + y + z; |
[200fcb3] | 61 | sout | "z:" | z; |
[4c8f86b3] | 62 | z = z = x; |
[200fcb3] | 63 | sout | "z:" | z; |
[4c8f86b3] | 64 | z = x - y - z; |
[200fcb3] | 65 | sout | "z:" | z; |
[4c8f86b3] | 66 | z = x * y * z; |
[200fcb3] | 67 | sout | "z:" | z; |
[4c8f86b3] | 68 | z = x * 3; |
[200fcb3] | 69 | sout | "z:" | z; |
[4c8f86b3] | 70 | z = 3 * x; |
[200fcb3] | 71 | sout | "z:" | z; |
[4c8f86b3] | 72 | z = x / 3; |
[200fcb3] | 73 | sout | "z:" | z; |
74 | sout | div( x, 3 ) | x / 3 | "," | x % 3; | |
[4c8f86b3] | 75 | [ x, y ] = div( x, 3 ); |
[200fcb3] | 76 | sout | "x:" | x | "y:" | y; |
[4c8f86b3] | 77 | |
[5ea5b28] | 78 | sout | nl; |
[4c8f86b3] | 79 | |
[1ae39f6e] | 80 | sin | x | y | z; |
[200fcb3] | 81 | sout | x | y | z; |
[1ae39f6e] | 82 | |
[5ea5b28] | 83 | sout | nl; |
[1ae39f6e] | 84 | |
[200fcb3] | 85 | sout | "Fibonacci Numbers"; |
[4c8f86b3] | 86 | Int fn, fn1, fn2; |
87 | fn = (Int){0}; fn1 = fn; // 1st case | |
[200fcb3] | 88 | sout | (int)0 | fn; |
[18c55e1] | 89 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case |
[200fcb3] | 90 | sout | 1 | fn; |
[ae4af81] | 91 | for ( i; 2u ~= 200 ) { |
[4c8f86b3] | 92 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
[200fcb3] | 93 | sout | i | fn; |
[4c8f86b3] | 94 | } // for |
95 | ||
[5ea5b28] | 96 | sout | nl; |
[4c8f86b3] | 97 | |
[200fcb3] | 98 | sout | "Factorial Numbers"; |
[f802e46] | 99 | Int fact = 1; // 1st case |
[200fcb3] | 100 | sout | (int)0 | fact; |
[ae4af81] | 101 | for ( i; 1u ~= 40u ) { |
[a933bcb3] | 102 | fact *= i; // general case |
[200fcb3] | 103 | sout | i | fact; |
[4c8f86b3] | 104 | } // for |
105 | } // main | |
106 | ||
107 | // Local Variables: // | |
108 | // tab-width: 4 // | |
[dc8511c] | 109 | // compile-command: "cfa gmp.cfa -lgmp" // |
[4c8f86b3] | 110 | // End: // |
Note: See TracBrowser
for help on using the repository browser.