Jump to content

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

m
Improved coding.
(New post.)
m (Improved coding.)
Line 5,021:
public static void main(String[] aArgs) {
List<CFData> cfData = List.of(
new CFData("[1; 5, 2] + 1/2 ", new int[] { 2, 1, 0, 2 }, (CFIterator) new r2cfIteratorR2cfIterator(13, 11) ),
new CFData("[3; 7] + 1/2 ", new int[] { 2, 1, 0, 2 }, (CFIterator) new r2cfIteratorR2cfIterator(22, 7) ),
new CFData("[3; 7] divided by 4 ", new int[] { 1, 0, 0, 4 }, (CFIterator) new r2cfIteratorR2cfIterator(22, 7) ),
new CFData("sqrt(2) ", new int[] { 0, 1, 1, 0 }, (CFIterator) new reciprocalRoot2ReciprocalRoot2() ),
new CFData("1 / sqrt(2) ", new int[] { 0, 1, 1, 0 }, (CFIterator) new root2Root2() ),
new CFData("(1 + sqrt(2)) / 2 ", new int[] { 1, 1, 0, 2 }, (CFIterator) new root2Root2() ),
new CFData("(1 + 1 / sqrt(2)) / 2", new int[] { 1, 1, 0, 2 }, (CFIterator) new reciprocalRoot2ReciprocalRoot2() ) );
for ( CFData data : cfData ) {
Line 5,058:
 
public void ingress(int aN) {
int temp = a; a = a1; a1 = temp + a1 * aN;
a temp = a1b; b = b1; b1 = temp + b1 * aN;
a1 = temp + a1 * aN;
temp = b;
b = b1;
b1 = temp + b1 * aN;
}
 
public int egress() {
final int n = a / b;
int temp = a; a = b; b = temp - b * n;
a temp = ba1; a1 = b1; b1 = temp - b1 * n;
b = temp - b * n;
temp = a1;
a1 = b1;
b1 = temp - b1 * n;
return n;
}
Line 5,083 ⟶ 5,075:
public int egressDone() {
if ( needsTerm() ) {
a = a1;
b = b1;
}
Line 5,103 ⟶ 5,095:
}
private static class r2cfIteratorR2cfIterator extends CFIterator {
public r2cfIteratorR2cfIterator(int aNumerator, int aDenominator) {
numerator = aNumerator; denominator = aDenominator;
}
Line 5,125 ⟶ 5,117:
}
 
private static class root2Root2 extends CFIterator {
public root2Root2() {
firstReturn = true;
}
Line 5,147 ⟶ 5,139:
}
private static class reciprocalRoot2ReciprocalRoot2 extends CFIterator {
public reciprocalRoot2ReciprocalRoot2() {
firstReturn = true;
secondReturn = true;
895

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.