Permalink
Browse files

Fixed power of function.

  • Loading branch information...
1 parent 51e8f83 commit 2f6cb40c3a774c522110c5804807f4bd2e2a3487 @svenstaro committed Dec 5, 2010
Showing with 11 additions and 30 deletions.
  1. +11 −30 main.cpp
View
@@ -13,13 +13,17 @@
#include <iostream>
#include <string>
-#define PRECISION 10
+#define PRECISION 100000
mpf_class mpf_pow(mpf_class base, mpf_class exp) {
mpf_class num(base, PRECISION);
- while(exp > 1) {
- num *= base;
- --exp;
+ if(exp == 0) {
+ num = 1;
+ } else {
+ while(exp > 1) {
+ num *= base;
+ --exp;
+ }
}
return num;
@@ -31,8 +35,7 @@ int main() {
mpf_class pi(0, PRECISION);
mpf_class n(PRECISION, PRECISION);
for(mpf_class i(0, PRECISION); i < n; ++i) {
- //pi += (
- std::cout << (
+ pi += (
(mpf_pow(-1, i)/mpf_pow(2, 10 * i)) * (
-(mpf_pow(2, 5)/(4 * i + 1)) -
1/(4 * i + 3) +
@@ -42,32 +45,10 @@ int main() {
mpf_pow(2, 2)/(10 * i + 7) +
1/(10 * i + 9)
)
- ) << std::endl;
+ );
}
pi = (1/mpf_pow(2, 6)) * pi;
- //std::cout << pi << std::endl;
-
-
- std::cout << "//////////////////" << std::endl;
-
- long double pi_lol = 0;
- long double n_lol = PRECISION;
- for(long double i = 0; i < n_lol; ++i) {
- //pi_lol += (
- std::cout << (
- (pow(-1, i)/pow(2, 10 * i)) * (
- -(pow(2, 5)/(4 * i + 1)) -
- 1/(4 * i + 3) +
- pow(2, 8)/(10 * i + 1) -
- pow(2, 6)/(10 * i + 3) -
- pow(2, 2)/(10 * i + 5) -
- pow(2, 2)/(10 * i + 7) +
- 1/(10 * i + 9)
- )
- ) << std::endl;
- }
- pi_lol = (1/pow(2, 6)) * pi_lol;
- //std::cout << pi_lol << std::endl;
+ std::cout << pi << std::endl;
return 0;
}

0 comments on commit 2f6cb40

Please sign in to comment.