Variable type to hold largest whole number

G

Guest

Which variable type (c#) can whole the largest whole number? I know this
sounds silly but as double and decimal are made for numbers with decimals I
am not sure.

Also if anybody knows of any library for .NET that would allow me to deal
with **VERY** large whole numbers.

Thanks in advance

JT.
 
V

Vadym Stetsyak

Hello, John!

J> Which variable type (c#) can whole the largest whole number? I know
J> this
J> sounds silly but as double and decimal are made for numbers with
J> decimals I
J> am not sure.

J> Also if anybody knows of any library for .NET that would allow me to
J> deal
J> with **VERY** large whole numbers.

maybe you unsingned long will satisfy your needs?

ulong type has the foollowing range
0 to 18,446,744,073,709,551,615

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
J

Jon Skeet [C# MVP]

John said:
Which variable type (c#) can whole the largest whole number? I know this
sounds silly but as double and decimal are made for numbers with decimals I
am not sure.

Also if anybody knows of any library for .NET that would allow me to deal
with **VERY** large whole numbers.

Well, what are your restrictions? For instance, the range of double is
much greater than the range of decimal, and it will store a bigger
whole number - but it won't store *every* whole number within that
range accurately.

Decimal, however, can never become "inaccurate" at 0DP - in other
words, it will always accurately represent whole numbers, and it can
store any whole number within its range.
 
G

Guest

By whole number I mean: A number that doesn't contain a fraction, so not too
sure what you mean by "can never become 'inaccurate' " basically I am trying
to write a program that finds primary numbers I have been told that once I
reach the limit of what a variable type can hold and lets say add 1, it
doesn’t through an error it just provides me with an incorrect "random"
number. Thus why I want to find out what is the best variable type to for
this project (find primary numbers) and also know what the limitations are
within the .net framework for very long numbers and whether there are any
special classes (free or commercial to hold very large numbers
hundred/thousands of digits).
 
J

Jon Skeet [C# MVP]

John said:
By whole number I mean: A number that doesn't contain a fraction, so not too
sure what you mean by "can never become 'inaccurate' " basically I am trying
to write a program that finds primary numbers I have been told that once I
reach the limit of what a variable type can hold and lets say add 1, it
doesn?t through an error it just provides me with an incorrect "random"
number.

Well, it won't provide you with a random number, but a whole number
stored in a double + 1 may well not give you a whole number - and the
next exactly representable integer may well be significantly more.
Thus why I want to find out what is the best variable type to for
this project (find primary numbers) and also know what the limitations are
within the .net framework for very long numbers and whether there are any
special classes (free or commercial to hold very large numbers
hundred/thousands of digits).

If you want to go above 28 digits, you'll need to use a 3rd party class
- otherwise Decimal should be okay for you.

http://www.codeproject.com/csharp/biginteger.asp may be of interest to
you.
 
G

Guest

Very useful thank a lot Jon!

Jon Skeet said:
Well, it won't provide you with a random number, but a whole number
stored in a double + 1 may well not give you a whole number - and the
next exactly representable integer may well be significantly more.


If you want to go above 28 digits, you'll need to use a 3rd party class
- otherwise Decimal should be okay for you.

http://www.codeproject.com/csharp/biginteger.asp may be of interest to
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top