文栏 - 信息技术 - 浏览文章 - Big number calculations in C#
Big number calculations in C#
发布时间: 2009/1/14 22:43:45 作者: Pavel Sem 出处: http://pavelsem.blogspot.com/
I needed to work with very big numbers (numbers which exceeded int or long types). Imagine for example you need to calculate factorial of 100 or even 1000 or more. How can you do this? The algorithm of factorial calculation is easy but how can you store the result? You can think out solution where you can store your big numbers like strings but solution like this can be difficult to implement. You have to implement own math operation on the string etc.

The other solution is to use F# math library. Because F# is also .NET language you can use it from other .NET languages e.g. C#. So what you need to start? What is necessary to install? F# downloads are available on Microsoft research pages. After you download F# libraries you need to install it and simply create new project in Visual Studio and the FSharp.Core.dll library as reference.

Example calculation of factorial using F# classes:

using System;
using Microsoft.FSharp.Math;

namespace BigNumberCSharp
{
   public class TestFactorial
   {
       public void CalculateFactorial(int x)
       {
           BigInt factorial = BigIntModule.factorial(BigInt.FromInt32(x));
           Console.WriteLine(factorial);
       }
   }
}

link:http://pavelsem.blogspot.com/2008/04/big-number-calculations-in-c.html
F# Download:http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/release.aspx
所属分类: 信息技术   所属专题: 他山之石
共有 8540 人次浏览

相关文章
    评论作者:
    电子邮件:
    评论内容:
    投票评价:
    验 证 码:
    图片包含4个随机字符,点击刷新
    请输入上面图片中的随机字符