Big Number
-
I need to work with some very large integers; about 100 decimal places. Therefore, I thought I would use the data type BigInteger. However, the following program does not compile:
using System;
using System.IO;
using System.Numeric;class MainClass {
public static void Main()
{
BigInteger i1;
}
}I get the following error message: Error 1 'System.Numeric.BigInteger' is inaccessible due to its protection level C:\dev\C#.dev\test\main.cs 8 9 test Should I be using a different data type? Why does this simple program not compile? Thanks Bob
-
I need to work with some very large integers; about 100 decimal places. Therefore, I thought I would use the data type BigInteger. However, the following program does not compile:
using System;
using System.IO;
using System.Numeric;class MainClass {
public static void Main()
{
BigInteger i1;
}
}I get the following error message: Error 1 'System.Numeric.BigInteger' is inaccessible due to its protection level C:\dev\C#.dev\test\main.cs 8 9 test Should I be using a different data type? Why does this simple program not compile? Thanks Bob
That bizarre message is what one gets when compiling with an old .NET version. BigInteger type got introduced in .NET 4.0, hence this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
BigInteger a = 12;
Console.WriteLine("a=" + a);
Console.ReadKey();
}
}
}works just fine on Visual Studio 10, targetting .NET 4.0 Please note the extra s in the using statement. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
That bizarre message is what one gets when compiling with an old .NET version. BigInteger type got introduced in .NET 4.0, hence this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
BigInteger a = 12;
Console.WriteLine("a=" + a);
Console.ReadKey();
}
}
}works just fine on Visual Studio 10, targetting .NET 4.0 Please note the extra s in the using statement. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Thanks for the response. I am back on version 3.5. Is there a bignum class in version 3.5? If so, what is it? Bob
No. However you could: - create your own; which is a painful job, the size of which depends on the exact operations you want available. Addition and multiplication are easy; division, and square rooting are hard; everything else is hard if you want maximum performance. - read some CP articles on such subject (I once did that and I must warn you they have wildly varying quality) - try and use a very old Java implementation (it used to also be part of Microsoft's defunct Visual J#, search for vsjlib.dll) - look inside the .NET 4.0 implementation and port that to .NET any version using Reflector or some such; - conclude that the one real solution is called .NET 4.0 :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
No. However you could: - create your own; which is a painful job, the size of which depends on the exact operations you want available. Addition and multiplication are easy; division, and square rooting are hard; everything else is hard if you want maximum performance. - read some CP articles on such subject (I once did that and I must warn you they have wildly varying quality) - try and use a very old Java implementation (it used to also be part of Microsoft's defunct Visual J#, search for vsjlib.dll) - look inside the .NET 4.0 implementation and port that to .NET any version using Reflector or some such; - conclude that the one real solution is called .NET 4.0 :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
Thanks for the response. I downloaded the Express Version of Studio 2010 which I believe is current. There is a newer version but it is in beta. I tried your code and I got the error message: Error 1 The type or namespace name 'Numerics' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\dev\C#.dev\test\main.cs 4 14 test It does not like the statement:
using System.Numerics;
What am I missing? Bob
-
Thanks for the response. I downloaded the Express Version of Studio 2010 which I believe is current. There is a newer version but it is in beta. I tried your code and I got the error message: Error 1 The type or namespace name 'Numerics' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\dev\C#.dev\test\main.cs 4 14 test It does not like the statement:
using System.Numerics;
What am I missing? Bob
The answer is in the error message: you should add a reference. Check the MSDN documentation on the types you want to use, it will tell you which namespaces you need to add a reference to, then do so in the solution pane. BTW: this has been the way since .NET 1.0; you get a limited number of DLL's referenced for free, everything else you have to add explicitly. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum