// File: aisthesis[P]realnumber/src/find_pi.cpp
// Function: main
int main(int argc, const char * argv[])
{
	//karatsuba::say_hello();

	string str = "1.0";
	RealNumber x(str);
	cout << "x is " << x.to_decimal_string() << endl;
	str = "300000000.0";
	RealNumber y(str);
	cout << "y is " << y.to_decimal_string() << endl;

	try {
		RealNumber("10000000000.0");
	} 
	catch (invalid_argument& ia) {
		cout << ia.what() << endl;
	}
	catch (exception& e) {
		cout << "this exception is expected" << endl;
	}
	RealNumber z = x / y;
	cout << "z is " << z.to_decimal_string() << endl;
	cout << "x.difference(y) is " << x.difference(y).to_decimal_string() << endl;
	
	RealNumber num("2.0");
	RealNumber guess("1.4");
	int iterations = 10;
	
	RealNumber sqrt_two = ConvergentSeries::babylonian_sqrt(num, guess, iterations);
	
	cout << "Square root of 2 is " << sqrt_two.to_decimal_string() << endl;
	cout << "or: " << ConvergentSeries::babylonian_sqrt(RealNumber("2.0"), RealNumber("1.4"), 
																											iterations).to_decimal_string() << endl;
	
	RealNumber pi = ConvergentSeries::gauss_legendre_pi(6, 10, sqrt_two);
	cout << "Pi is\n" << pi.to_decimal_string() << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x22a0
movq -0x288(%rbp), %rdx
leaq 0x3b2d(%rip), %rsi      # 0x6004
leaq -0x30(%rbp), %rdi
callq 0x2f70
jmp 0x24e2
leaq -0x31(%rbp), %rdi
callq 0x21a0
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3340
jmp 0x24fa
movq 0x5ac7(%rip), %rdi      # 0x7fc8
leaq 0x3b00(%rip), %rsi      # 0x6008
callq 0x2160
movq %rax, -0x290(%rbp)
jmp 0x2516
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3680
jmp 0x2525
movq -0x290(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2140
movq %rax, -0x298(%rbp)
jmp 0x253e
movq -0x298(%rbp), %rdi
movq 0x5a5c(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x2553
leaq -0x70(%rbp), %rdi
callq 0x20a0
leaq 0x3aab(%rip), %rsi      # 0x600e
leaq -0x30(%rbp), %rdi
callq 0x2230
jmp 0x256e
leaq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3340
jmp 0x257d
movq 0x5a44(%rip), %rdi      # 0x7fc8
leaq 0x3a8f(%rip), %rsi      # 0x601a
callq 0x2160
movq %rax, -0x2a0(%rbp)
jmp 0x2599
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3680
jmp 0x25ab
movq -0x2a0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2140
movq %rax, -0x2a8(%rbp)
jmp 0x25c7
movq -0x2a8(%rbp), %rdi
movq 0x59d3(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x25dc
leaq -0x98(%rbp), %rdi
callq 0x20a0
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x22a0
movq -0x2b0(%rbp), %rdx
leaq 0x3a17(%rip), %rsi      # 0x6020
leaq -0xc0(%rbp), %rdi
callq 0x2f70
jmp 0x2617
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3340
jmp 0x262c
leaq -0xa0(%rbp), %rdi
callq 0x3650
leaq -0xc0(%rbp), %rdi
callq 0x20a0
leaq -0xc1(%rbp), %rdi
callq 0x21a0
jmp 0x2777
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x21a0
jmp 0x2f58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x20a0
jmp 0x2f46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x20a0
jmp 0x2f3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x26ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x20a0
leaq -0xc1(%rbp), %rdi
callq 0x21a0
movl -0x44(%rbp), %eax
movl %eax, -0x2b4(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2c71
movq -0x40(%rbp), %rdi
callq 0x2070
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0x587d(%rip), %rdi      # 0x7fc8
callq 0x2160
movq %rax, -0x2c0(%rbp)
jmp 0x2759
movq -0x2c0(%rbp), %rdi
movq 0x5841(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x276e
callq 0x2260
jmp 0x2775
jmp 0x2777
leaq -0xe0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x3fe0
jmp 0x278d
movq 0x5834(%rip), %rdi      # 0x7fc8
leaq 0x38ae(%rip), %rsi      # 0x6049
callq 0x2160
movq %rax, -0x2c8(%rbp)
jmp 0x27a9
leaq -0x100(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3680
jmp 0x27be
movq -0x2c8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x2140
movq %rax, -0x2d0(%rbp)
jmp 0x27da
movq -0x2d0(%rbp), %rdi
movq 0x57c0(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x27ef
leaq -0x100(%rbp), %rdi
callq 0x20a0
movq 0x57c6(%rip), %rdi      # 0x7fc8
leaq 0x3846(%rip), %rsi      # 0x604f
callq 0x2160
movq %rax, -0x2d8(%rbp)
jmp 0x2817
leaq -0x128(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x3d00
jmp 0x282d
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x3680
jmp 0x2842
movq -0x2d8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x2140
movq %rax, -0x2e0(%rbp)
jmp 0x285e
movq -0x2e0(%rbp), %rdi
movq 0x573c(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x2873
leaq -0x120(%rbp), %rdi
callq 0x20a0
leaq -0x128(%rbp), %rdi
callq 0x3650
leaq -0x151(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x22a0
movq -0x2e8(%rbp), %rdx
leaq 0x37b7(%rip), %rsi      # 0x6063
leaq -0x150(%rbp), %rdi
callq 0x2f70
jmp 0x28ba
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3340
jmp 0x28cf
leaq -0x150(%rbp), %rdi
callq 0x20a0
leaq -0x151(%rbp), %rdi
callq 0x21a0
leaq -0x181(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x22a0
movq -0x2f0(%rbp), %rdx
leaq 0x375f(%rip), %rsi      # 0x6067
leaq -0x180(%rbp), %rdi
callq 0x2f70
jmp 0x2916
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x3340
jmp 0x292b
leaq -0x180(%rbp), %rdi
callq 0x20a0
leaq -0x181(%rbp), %rdi
callq 0x21a0
movl $0xa, -0x188(%rbp)
movslq -0x188(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x160(%rbp), %rdx
leaq -0x198(%rbp), %rcx
callq 0x40f0
jmp 0x297e
movq 0x5643(%rip), %rdi      # 0x7fc8
leaq 0x36df(%rip), %rsi      # 0x606b
callq 0x2160
movq %rax, -0x2f8(%rbp)
jmp 0x299a
leaq -0x1b8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x3680
jmp 0x29af
movq -0x2f8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x2140
movq %rax, -0x300(%rbp)
jmp 0x29cb
movq -0x300(%rbp), %rdi
movq 0x55cf(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x29e0
leaq -0x1b8(%rbp), %rdi
callq 0x20a0
movq 0x55d5(%rip), %rdi      # 0x7fc8
leaq 0x3686(%rip), %rsi      # 0x6080
callq 0x2160
movq %rax, -0x308(%rbp)
jmp 0x2a08
leaq -0x209(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x22a0
movq -0x310(%rbp), %rdx
leaq 0x363a(%rip), %rsi      # 0x6063
leaq -0x208(%rbp), %rdi
callq 0x2f70
jmp 0x2a37
leaq -0x1e8(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x3340
jmp 0x2a4c
leaq -0x239(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x22a0
movq -0x318(%rbp), %rdx
leaq 0x35fa(%rip), %rsi      # 0x6067
leaq -0x238(%rbp), %rdi
callq 0x2f70
jmp 0x2a7b
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x3340
jmp 0x2a90
movslq -0x188(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
leaq -0x218(%rbp), %rdx
leaq -0x248(%rbp), %rcx
callq 0x40f0
jmp 0x2ac1
leaq -0x1d8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x3680
jmp 0x2ad6
movq -0x308(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x2140
movq %rax, -0x320(%rbp)
jmp 0x2af2
movq -0x320(%rbp), %rdi
movq 0x54a8(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x2b07
leaq -0x1d8(%rbp), %rdi
callq 0x20a0
leaq -0x1e0(%rbp), %rdi
callq 0x3650
leaq -0x218(%rbp), %rdi
callq 0x3650
leaq -0x238(%rbp), %rdi
callq 0x20a0
leaq -0x239(%rbp), %rdi
callq 0x21a0
leaq -0x1e8(%rbp), %rdi
callq 0x3650
leaq -0x208(%rbp), %rdi
callq 0x20a0
leaq -0x209(%rbp), %rdi
callq 0x21a0
movq $0x6, -0x258(%rbp)
movq $0xa, -0x260(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x258(%rbp), %rsi
leaq -0x260(%rbp), %rdx
leaq -0x190(%rbp), %rcx
callq 0x42f0
jmp 0x2ba0
movq 0x5421(%rip), %rdi      # 0x7fc8
leaq 0x34d7(%rip), %rsi      # 0x6085
callq 0x2160
movq %rax, -0x328(%rbp)
jmp 0x2bbc
leaq -0x280(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x3680
jmp 0x2bd1
movq -0x328(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x2140
movq %rax, -0x330(%rbp)
jmp 0x2bed
movq -0x330(%rbp), %rdi
movq 0x53ad(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x2c02
leaq -0x280(%rbp), %rdi
callq 0x20a0
leaq -0x250(%rbp), %rdi
callq 0x3650
leaq -0x190(%rbp), %rdi
callq 0x3650
leaq -0x160(%rbp), %rdi
callq 0x3650
leaq -0x130(%rbp), %rdi
callq 0x3650
leaq -0xe0(%rbp), %rdi
callq 0x3650
leaq -0x78(%rbp), %rdi
callq 0x3650
leaq -0x50(%rbp), %rdi
callq 0x3650
leaq -0x30(%rbp), %rdi
callq 0x20a0
movl -0x4(%rbp), %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movl -0x2b4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2f3d
movq -0x40(%rbp), %rdi
callq 0x2070
movq %rax, -0xd0(%rbp)
movq 0x532d(%rip), %rdi      # 0x7fc8
leaq 0x338c(%rip), %rsi      # 0x602e
callq 0x2160
movq %rax, -0x338(%rbp)
jmp 0x2cb0
movq -0x338(%rbp), %rdi
movq 0x52ea(%rip), %rsi      # 0x7fa8
callq 0x2180
jmp 0x2cc5
callq 0x2260
jmp 0x2ccc
jmp 0x2777
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x2260
jmp 0x2ce4
jmp 0x2f3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x2260
jmp 0x2cfc
jmp 0x2f3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x20a0
jmp 0x2f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2d55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x20a0
leaq -0x128(%rbp), %rdi
callq 0x3650
jmp 0x2f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2d8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x20a0
leaq -0x151(%rbp), %rdi
callq 0x21a0
jmp 0x2f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2dc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x20a0
leaq -0x181(%rbp), %rdi
callq 0x21a0
jmp 0x2f25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x20a0
jmp 0x2f0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2ecd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2ec1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2ea9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x20a0
leaq -0x1e0(%rbp), %rdi
callq 0x3650
leaq -0x218(%rbp), %rdi
callq 0x3650
leaq -0x238(%rbp), %rdi
callq 0x20a0
leaq -0x239(%rbp), %rdi
callq 0x21a0
leaq -0x1e8(%rbp), %rdi
callq 0x3650
leaq -0x208(%rbp), %rdi
callq 0x20a0
leaq -0x209(%rbp), %rdi
callq 0x21a0
jmp 0x2f0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x20a0
leaq -0x250(%rbp), %rdi
callq 0x3650
leaq -0x190(%rbp), %rdi
callq 0x3650
leaq -0x160(%rbp), %rdi
callq 0x3650
leaq -0x130(%rbp), %rdi
callq 0x3650
leaq -0xe0(%rbp), %rdi
callq 0x3650
leaq -0x78(%rbp), %rdi
callq 0x3650
leaq -0x50(%rbp), %rdi
callq 0x3650
leaq -0x30(%rbp), %rdi
callq 0x20a0
movq -0x40(%rbp), %rdi
callq 0x2290
movq %rax, %rdi
callq 0x3020
nopl (%rax)