Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Big Number

Big Number

Scheduled Pinned Locked Moved C#
questioncsharphelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobInNJ
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • B BobInNJ

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • L Luc Pattyn

        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

        B Offline
        B Offline
        BobInNJ
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • B BobInNJ

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • L Luc Pattyn

            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

            B Offline
            B Offline
            BobInNJ
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • B BobInNJ

              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

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups