Arbitrary Precision for decimals in C# help?

Here is my current code for computing Pi using the chudnovsky method in c#:

using System;
using System.Diagnostics;
using System.IO;
using java.math;

namespace pi.chudnovsky
    public class Program
        static Double Factorial(Double fact)
            //begin factorial function
            if (fact <= 1)
                return 1;
                return fact * Factorial(fact - 1); //loops multiplication until the factorial is reached
        static Double doSummation(Double maxPower)
            //begin chudnovsky summation function
            Double sum = 0;
            for (int i = 0; i <= maxPower; i++) //starts at i=0
                sum += ((Math.Pow(-1, i)) * Factorial(6 * i) * (13591409 + 5451401 * i)) / (Factorial(3 * i) * Factorial(i) * Factorial(i) * Factorial(i) * Math.Pow(640320, (3 * i + 1.5))); //chudnovsky algorithm
            return sum;
        static void Main(string[] args)
            int num;
            Console.WriteLine("Enter how many terms to compute Chudnovsky summation: ");
            //begin stopwatch
            Stopwatch stopwatch = new Stopwatch();
            //parse user input
            num = Convert.ToInt32(Console.ReadLine());
            //perform calculation
            Double inv = 1 / (12 * doSummation(num));
            //stop stopwatch
            //display info
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed.TotalMilliseconds);
            //write to pi.txt
            TextWriter pi = new StreamWriter("pi.txt");
            //write to stats.txt
            TextWriter stats = new StreamWriter("stats.txt");

So, I've included the J# library, and included java.math. Now when I replace all the "double"s with "BigDecimal"s, I get these compile errors:

I know that this isn't the problem with me using Int for the loops, as it worked perfectly with Doubles. My question is, how do you resolve these errors relating to int and BigDecimal, or can you recommend another arbitrary precision library?

I've tried using XMPIR, have gotten everything to compile, but I get:

So I can I use p/invoke to include xmpir so I can use whatever the bigdecimal class is?

Thank you for your time!


Can you not convert your int's to BigDecimal's before comparing them?

I assume you understand the problem here is that there is no operator overload for the greater, less than, etc. signs on the BigDecimal class that accepts an int.

Need Your Help

mapReduce not calling map nor reduce

node.js mongodb map mapreduce aggregation-framework

I just started working with mongodb and I am having troubles using mapReduce function.

how to get X window id of a window created by glut

x11 glut

I created a window using glutCreateWindow( window_name);

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.