Jump to content

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

m
whitespace
(→‎Testing: ([0;3,2] + [1;5,2]) * ([0;3,2] - [1;5,2]))
m (whitespace)
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.
 
=={{header|C++}}==
<lang cpp>/* Implement matrix NG
/* Implement matrix NG
Nigel Galloway, February 12., 2013
*/
Line 89:
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){
}};</lang>
===Testing===
</lang>
 
==Testing==
[3;7] + [0;2]
<lang cpp>int main() {
int main() {
NG_8 a(0,1,1,0,0,0,0,1);
r2cf n2(22,7);
Line 107 ⟶ 104:
std::cout << std::endl;
return 0;
}</lang>
}
</lang>
{{out}}
<pre>
Line 115 ⟶ 111:
</pre>
[1:5,2] * [3;7]
<lang cpp>int main() {
int main() {
NG_8 b(1,0,0,0,0,0,0,1);
r2cf b1(13,11);
Line 127 ⟶ 122:
std::cout << std::endl;
return 0;
}</lang>
}
</lang>
{{out}}
<pre>
Line 135 ⟶ 129:
</pre>
[1:5,2] - [3;7]
<lang cpp>int main() {
int main() {
NG_8 c(0,1,-1,0,0,0,0,1);
r2cf c1(13,11);
Line 145 ⟶ 138:
std::cout << std::endl;
return 0;
}</lang>
}
</lang>
{{out}}
<pre>
Line 153 ⟶ 145:
</pre>
Divide [] by [3;7]
<lang cpp>int main() {
int main() {
NG_8 d(0,1,0,0,0,0,1,0);
r2cf d1(22*22,7*7);
Line 161 ⟶ 152:
std::cout << std::endl;
return 0;
}</lang>
}
</lang>
{{out}}
<pre>
Line 168 ⟶ 158:
</pre>
([0;3,2] + [1;5,2]) * ([0;3,2] - [1;5,2])
<lang cpp>int main() {
int main() {
r2cf a1(2,7);
r2cf a2(13,11);
Line 188 ⟶ 177:
std::cout << std::endl;
return 0;
}</lang>
}
</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.