Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

Content added Content deleted
(→‎Testing: ([0;3,2] + [1;5,2]) * ([0;3,2] - [1;5,2]))
m (whitespace)
Line 59: Line 59:


When performing arithmetic operation on two potentially infinite continued fractions it is possible to generate a rational number. eg <math>\sqrt{2}</math> * <math>\sqrt{2}</math> should produce 2. This will require either that I determine that my internal state is approaching infinity, or limiting the number of terms I am willing to input without producing any output.
When performing arithmetic operation on two potentially infinite continued fractions it is possible to generate a rational number. eg <math>\sqrt{2}</math> * <math>\sqrt{2}</math> should produce 2. This will require either that I determine that my internal state is approaching infinity, or limiting the number of terms I am willing to input without producing any output.

=={{header|C++}}==
=={{header|C++}}==
<lang cpp>
<lang cpp>/* Implement matrix NG
/* Implement matrix NG
Nigel Galloway, February 12., 2013
Nigel Galloway, February 12., 2013
*/
*/
Line 89: Line 89:
public:
public:
NG_8(int a12, int a1, int a2, int a, int b12, int b1, int b2, int b): a12(a12), a1(a1), a2(a2), a(a), b12(b12), b1(b1), b2(b2), b(b){
NG_8(int a12, int a1, int a2, int a, int b12, int b1, int b2, int b): a12(a12), a1(a1), a2(a2), a(a), b12(b12), b1(b1), b2(b2), b(b){
}};
}};</lang>
===Testing===
</lang>

==Testing==
[3;7] + [0;2]
[3;7] + [0;2]
<lang cpp>
<lang cpp>int main() {
int main() {
NG_8 a(0,1,1,0,0,0,0,1);
NG_8 a(0,1,1,0,0,0,0,1);
r2cf n2(22,7);
r2cf n2(22,7);
Line 107: Line 104:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 115: Line 111:
</pre>
</pre>
[1:5,2] * [3;7]
[1:5,2] * [3;7]
<lang cpp>
<lang cpp>int main() {
int main() {
NG_8 b(1,0,0,0,0,0,0,1);
NG_8 b(1,0,0,0,0,0,0,1);
r2cf b1(13,11);
r2cf b1(13,11);
Line 127: Line 122:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 135: Line 129:
</pre>
</pre>
[1:5,2] - [3;7]
[1:5,2] - [3;7]
<lang cpp>
<lang cpp>int main() {
int main() {
NG_8 c(0,1,-1,0,0,0,0,1);
NG_8 c(0,1,-1,0,0,0,0,1);
r2cf c1(13,11);
r2cf c1(13,11);
Line 145: Line 138:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 153: Line 145:
</pre>
</pre>
Divide [] by [3;7]
Divide [] by [3;7]
<lang cpp>
<lang cpp>int main() {
int main() {
NG_8 d(0,1,0,0,0,0,1,0);
NG_8 d(0,1,0,0,0,0,1,0);
r2cf d1(22*22,7*7);
r2cf d1(22*22,7*7);
Line 161: Line 152:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 168: Line 158:
</pre>
</pre>
([0;3,2] + [1;5,2]) * ([0;3,2] - [1;5,2])
([0;3,2] + [1;5,2]) * ([0;3,2] - [1;5,2])
<lang cpp>
<lang cpp>int main() {
int main() {
r2cf a1(2,7);
r2cf a1(2,7);
r2cf a2(13,11);
r2cf a2(13,11);
Line 188: Line 177:
std::cout << std::endl;
std::cout << std::endl;
return 0;
return 0;
}</lang>
}
</lang>