numbers of arbitary size

  • Thread starter Thread starter Gilbert Röhrbein
  • Start date Start date
G

Gilbert Röhrbein

Hi coders,

I want to calculate big prime numbers. To test if a number is prime i want
to use the Miller-Rabin-Algo, but the calculation of "2^x" (for x > 1023)
isn't possible with datatypes like "double". The result is simply to big.
For example my C# calc says that "(2^1024) - (2^1024 + 1)" isn't 1. To
calculate numbers of arbitary size i can't use the standardized datatypes
of C# .NET.

The GNU MP is a package to handle with numbers of arbitary size. But it is
programmed for C and GNU compilers.

My question is: Is there a useful package(or a portation of GNU MP) for C#
..NET to calc numbers of arbitary size?

Though they know that bignums are essential for scientific calcs, MS
wasn't so friendly to bring a bignum datatype with the .NET Framework.

Gilbert Röhrbein
 
You can use the J# runtime library, which comes with .NET.

If using VS.NET, add a reference to "vjslib" from the .NET tab of the
Add Reference dialog.



Then use the java.math.BigInteger or BigDecimal classes.
The sample below calculates 2^2048:

class Program
{
static void Main(string[] args)
{
java.math.BigInteger num = new java.math.BigInteger("2");
Console.WriteLine( num.pow(2048) );
}
}


Joshua Flanagan
http://flimflan.com/blog
 
Joshua Flanagan said:
You can use the J# runtime library, which comes with .NET.

Or download it here:
http://msdn.microsoft.com/vjsharp/downloads/howtoget/default.aspx
If using VS.NET, add a reference to "vjslib" from the .NET tab of the
Add Reference dialog.

Then use the java.math.BigInteger or BigDecimal classes.
The sample below calculates 2^2048:

class Program
{
static void Main(string[] args)
{
java.math.BigInteger num = new java.math.BigInteger("2");
Console.WriteLine( num.pow(2048) );
}
}

Thx a lot. That's exactly what I looked for.

Gilbert Röhrbein
</>
 
Back
Top