Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions
Content added Content deleted
Line 2,620: | Line 2,620: | ||
end |
end |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
|||
To compile the program, you might try something like the following: |
|||
<pre>patscc -std=gnu2x -g -O2 -DATS_MEMALLOC_GCBDW $(pkg-config --cflags ats2-xprelude) $(pkg-config --variable=PATSCCFLAGS ats2-xprelude) continued-fraction-task.dats continued_fraction.{s,d}ats $(pkg-config --libs ats2-xprelude) -lgc -lm</pre> |
|||
You have to specify some C language standard, because patscc defaults to C99. |
|||
Then run the program by typing <pre>./a.out</pre> |
|||
The output should resemble that of the Standard ML program from which the ATS was translated. Minus signs might look different: |
|||
<pre> |
|||
golden ratio => [1;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...] (1 + sqrt(5))/2 |
|||
silver ratio => [2;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,...] (1 + sqrt(2)) |
|||
sqrt2 => [1;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,...] |
|||
sqrt5 => [2;4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,...] |
|||
1/4 => [0;4] |
|||
1/3 => [0;3] |
|||
1/2 => [0;2] |
|||
2/3 => [0;1,2] |
|||
3/4 => [0;1,3] |
|||
13/11 => [1;5,2] |
|||
22/7 => [3;7] approximately pi |
|||
0 => [0] |
|||
1 => [1] |
|||
2 => [2] |
|||
3 => [3] |
|||
4 => [4] |
|||
4 + 3 => [7] |
|||
4 - 3 => [1] |
|||
4 * 3 => [12] |
|||
4 / 3 => [1;3] |
|||
4 ** 3 => [64] |
|||
4 ** (-3) => [0;64] |
|||
negative 4 => [-4] |
|||
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method 1 |
|||
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method 2 |
|||
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method 3 |
|||
sqrt2 + sqrt2 => [2;1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] |
|||
sqrt2 - sqrt2 => [0] |
|||
sqrt2 * sqrt2 => [2] |
|||
sqrt2 / sqrt2 => [1] |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |