Calculating PI in .NET

Friday, December 30, 2011

I always loved mathematics. Although I’m certainly not a mathematician by profession, I’m always intrigued and inspired by math’s pureness and cleverness. One of the simplest and fascinating aspects of math is the number PI. Described simply as the ratio of a circle’s circumference to its diameter, it’s a constant with infinite digits after the decimal point and most importantly, non repeating (at least as far as I know). There are many ways to calculate PI, as evident within the PI Wikipedia link. I wanted to see how I can get a large number of digits of...
5 comments

BigInteger in .NET 4.0

Tuesday, May 26, 2009

One of the simplest new additions to the .NET 4.0 framework is an integer with arbitrary length, System.Numerics.BigInteger. Here’s a simple usage example, comparing it to a double:   BigInteger b = BigInteger.Pow(2, 64); Console.WriteLine("BigInteger: {0}", b.ToString("N")); Console.WriteLine("Double:     {0}", Math.Pow(2, 64).ToString("N")); Console.WriteLine(); b = BigInteger.Pow(2, 128); Console.WriteLine("BigInteger: {0}", b.ToString("N")); Console.WriteLine("Double:     {0}", ((double)b).ToString("N")); The output is: Not bad.
no comments