473,569 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable type to hold largest whole number

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
5 11025
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
John <Jo**@discussio ns.microsoft.co mwrote:
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.co m>
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
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**@discussio ns.microsoft.co mwrote:
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.co m>
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
John <Jo**@discussio ns.microsoft.co mwrote:
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.co m>
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
Very useful thank a lot Jon!

"Jon Skeet [C# MVP]" wrote:
John <Jo**@discussio ns.microsoft.co mwrote:
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.co m>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3386
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in the wrong direction with the implementation? I'm asking this because I don't have much experience with C++. Thanks in advance. The main problem...
4
3044
by: MCollins | last post by:
trying to determine a variable type, specifically that a variable is an integer. i tried using type(var) but that only seemed to produce a response in the command line. is there a built in python function to determine if a variable is an integer?
5
3794
by: frankhall36 | last post by:
Yeah, I need some help, I'm not a very good programmer but I've tried a lot of languages, and anyways, I want to start applying programming to physics, and I would like to learn how to make a Variable Type for a little program I am making. Basically a 32byte or up sized long double (which is 16 bytes from what I was told). I just really want...
3
9904
by: David Marsh | last post by:
The program calculates the continued fraction representation of the input: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv) { double diff, n, r, i; if(argc != 2) exit(EXIT_FAILURE);
6
4239
by: le0 | last post by:
Hi Guys, Can you help me with this? Is there any function that I can use in getting a whole number Example: Input OutPut 12.3 12 1.63 1
4
10881
by: adodotnet20 | last post by:
I'm developing a Windows application and I'm having some problems in making variable accessible to the whole application. I use VS.NET 2005 and I create a database connection object in the method private void connect_Click(object sender, EventArgs e). That object I create seems to be accessible only within that method, how do I make it...
4
10299
by: mouseit | last post by:
If I have a variable of some sort, say x, how can I find out what variable type javascript thinks it is? For example, if I've declared x as 5 earlier, how do I know now whether it's a string or a number, isNaN returns false, regardless of whether I declared it as "5" or 5.
1
3177
by: mertoman | last post by:
Hello, In Adobe LiveCycle Designer 8 I have a form field that users should be able to us to enter a whole number followed by a fraction or a decimal number such as: 45 1/8 or 45.125 I prefer to give the user the ability to enter a two digit whole number followed by a fraction in 16ths of an inch. The script should convert the...
10
4517
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an integer, it should return false, but it should work normally if the parameter is a float. To illustrate this, I attached a minimal example.
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.