Arbitrary-precision integers (included): Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo implementation) |
Not a robot (talk | contribs) (Add CLU) |
||
Line 408: | Line 408: | ||
(zero? (mod k 3)) (recur (* n n n) (/ k 3)) |
(zero? (mod k 3)) (recur (* n n n) (/ k 3)) |
||
:else (reduce * (repeat k n))))</lang> |
:else (reduce * (repeat k n))))</lang> |
||
=={{header|CLU}}== |
|||
This program uses the <code>bigint</code> type that is supplied with Portable CLU, in |
|||
<code>misc.lib</code>. The program must be merged with that library in order to work. |
|||
The type is not included in the CLU specification, however it is included as a library |
|||
with the reference implementation. |
|||
<lang clu>start_up = proc () |
|||
% Get bigint versions of 5, 4, 3 and 2 |
|||
five: bigint := bigint$i2bi(5) |
|||
four: bigint := bigint$i2bi(4) |
|||
three: bigint := bigint$i2bi(3) |
|||
two: bigint := bigint$i2bi(2) |
|||
% Calculate 5**4**3**2 |
|||
huge_no: bigint := five ** four ** three ** two |
|||
% Turn answer into string |
|||
huge_str: string := bigint$unparse(huge_no) |
|||
% Scan for first digit (the string will have some leading whitespace) |
|||
i: int := 1 |
|||
while huge_str[i] = ' ' do i := i + 1 end |
|||
po: stream := stream$primary_output() |
|||
stream$putl(po, "First 20 digits: " |
|||
|| string$substr(huge_str, i, 20)) |
|||
stream$putl(po, "Last 20 digits: " |
|||
|| string$substr(huge_str, string$size(huge_str)-19, 20)) |
|||
stream$putl(po, "Amount of digits: " |
|||
|| int$unparse(string$size(huge_str) - i + 1)) |
|||
end start_up</lang> |
|||
{{out}} |
|||
<pre>First 20 digits: 62060698786608744707 |
|||
Last 20 digits: 92256259918212890625 |
|||
Amount of digits: 183231</pre> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |