Created
December 12, 2012 17:54
-
-
Save maxdeliso/4270023 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <cmath> | |
/* | |
* mvc++: cl /EHsc /nologo /GL /Ox pi.cpp /link /LTCG:status /LTCG | |
*/ | |
int main() { | |
const int ITER_MAX = 1000000; | |
double x = 1.0; | |
double result = 0; | |
/* maclaurin polynomial for arctan(x) */ | |
for( | |
int i = 0; | |
i < ITER_MAX; | |
++i) { | |
result += | |
pow(-1, (double)i) * pow(x, 2.0*i+1) / (2*i+1); | |
} | |
/* pi = 4 * arctan(1) */ | |
double pi = 4 * result; | |
std::cout << "pi = " << std::scientific << pi << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
; 6 : const int ITER_MAX = 1000000;
; 7 :
; 8 : double x = 1.0;
; 9 : double result = 0;
00009 0f 57 c0 xorps xmm0, xmm0
0000c 56 push esi
0000d 57 push edi
0000e bf 01 00 00 00 mov edi, 1
00013 8b f7 mov esi, edi
00015 f2 0f 11 44 24
28 movsd QWORD PTR _result$[esp+64], xmm0
; 10 :
; 11 : /* maclaurin polynomial for arctan(x) */
; 12 : for(
; 13 : int i = 0;
0001b c7 44 24 20 00
00 00 00 mov DWORD PTR _i$21867[esp+64], 0
00023 89 74 24 24 mov DWORD PTR tv334[esp+64], esi
00027 eb 07 8d a4 24
00 00 00 00 npad 9
$LL41@main:
; 14 : i < ITER_MAX;
; 15 : ++i) {
; 16 : result +=
; 17 : pow(-1, (double)i) * pow(x, 2.0_i+1) / (2_i+1);
00030 d9 e8 fld1
00032 db 44 24 20 fild DWORD PTR _i$21867[esp+64]
00036 dd 54 24 30 fst QWORD PTR tv225[esp+64]
0003a dc c0 fadd ST(0), ST(0)
0003c d8 c1 fadd ST(0), ST(1)
0003e e8 00 00 00 00 call __CIpow
00043 dd 5c 24 38 fstp QWORD PTR tv313[esp+64]
00047 dd 05 00 00 00
00 fld QWORD PTR __real@bff0000000000000
0004d dd 44 24 30 fld QWORD PTR tv225[esp+64]
00051 e8 00 00 00 00 call __CIpow
00056 dc 4c 24 38 fmul QWORD PTR tv313[esp+64]
0005a 01 7c 24 20 add DWORD PTR _i$21867[esp+64], edi
0005e 83 c6 02 add esi, 2
00061 da 74 24 24 fidiv DWORD PTR tv334[esp+64]
00065 89 74 24 24 mov DWORD PTR tv334[esp+64], esi
00069 dc 44 24 28 fadd QWORD PTR _result$[esp+64]
0006d dd 5c 24 28 fstp QWORD PTR _result$[esp+64]
00071 81 fe 81 84 1e
00 cmp esi, 2000001 ; 001e8481H
00077 7c b7 jl SHORT $LL41@main
; 18 : }
; 19 :
; 20 : /* pi = 4* arctan(1) */
; 21 : double pi = 4 * result;
00079 f2 0f 10 44 24
28 movsd xmm0, QWORD PTR _result$[esp+64]
0007f f2 0f 59 05 00
00 00 00 mulsd xmm0, QWORD PTR __real@4010000000000000
00087 f2 0f 11 44 24
38 movsd QWORD PTR _pi$[esp+64], xmm0