By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

Variable type to hold largest whole number

P: n/a
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.
Oct 13 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hello, John!

JWhich variable type (c#) can whole the largest whole number? I know
Jthis
Jsounds silly but as double and decimal are made for numbers with
Jdecimals I
Jam not sure.

JAlso if anybody knows of any library for .NET that would allow me to
Jdeal
Jwith **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
Oct 13 '06 #2

P: n/a
John <Jo**@discussions.microsoft.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 13 '06 #3

P: n/a
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).

"Jon Skeet [C# MVP]" wrote:
John <Jo**@discussions.microsoft.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #4

P: n/a
John <Jo**@discussions.microsoft.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #5

P: n/a
Very useful thank a lot Jon!

"Jon Skeet [C# MVP]" wrote:
John <Jo**@discussions.microsoft.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.