469,306 Members | 1,881 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Very big numbers

hello,i'm working on some math problems and i want to answer a
question.
The biggest number i can store in a variable is 3-3.5 billion.
e.g
unsigned long int=3234567890;

is there a way a can store bigger numbers in a variable?

Sep 10 '07 #1
8 14383
tolkien wrote:
The biggest number i can store in a variable is 3-3.5 billion.
e.g
unsigned long int=3234567890;

is there a way a can store bigger numbers in a variable?
Maybe not, if you have ruled out long long int, double, long double,
logarithmic methods, and multiple precision libraries. What are your
constraints? This doesn't even look like a homework problem, unless you
have left something out.
Sep 10 '07 #2
It's not a homework problem :).i was just playing big numbers and i
wanted to
know if there was any other way!
Thank you for answering!!!

Sep 10 '07 #3
tolkien <gv****@gmail.comwrites:
hello,i'm working on some math problems and i want to answer a
question.
The biggest number i can store in a variable is 3-3.5 billion.
e.g
unsigned long int=3234567890;

is there a way a can store bigger numbers in a variable?
Yes, but that is not what you want to ask! I can store a large number
very easily like this:

char big[] = "323456789032345678903234567890";

but doing anything with it (other than printing it) is rather fiddly.
You need to say more about what you need from your numbers:

(1) If you want speed and range but can sacrifice precision, use
double.

(2) If you want speed and a somewhat wider range without
loosing any precision (and you have compiler that can do it) use long
long int.

(3) If you want an almost unlimited range *and* precision in a portable
program, use a "big num" package like GMP.

--
Ben.
Sep 10 '07 #4
tolkien pisze:
hello,i'm working on some math problems and i want to answer a
question.
The biggest number i can store in a variable is 3-3.5 billion.
e.g
unsigned long int=3234567890;

is there a way a can store bigger numbers in a variable?
There is always a way. ;)
As somebody already have stated, storing is not a problem.
But if you consider arithmetic, in general, you have two option:
1. Design your own data structures. (more fun, but why to reinvent
the wheel?)
2. Use one of libraries, for example:
http://en.wikipedia.org/wiki/GNU_Mul...cision_Library

ch.
Sep 11 '07 #5
On Mon, 10 Sep 2007 16:44:03 +0100, Ben Bacarisse wrote:
(2) If you want speed and a somewhat wider range without
loosing any precision (and you have compiler that can do it) use long
long int.
In many implementations long double is capable to hold any integer
up to ULLONG_MAX + 1 exactly, so it doesn't lose any precision
compared to long long. (It does compared to a bignum library, of
course.)
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 11 '07 #6
Army1987 <ar******@NOSPAM.itwrites:
On Mon, 10 Sep 2007 16:44:03 +0100, Ben Bacarisse wrote:
>(2) If you want speed and a somewhat wider range without
loosing any precision (and you have compiler that can do it) use long
long int.

In many implementations long double is capable to hold any integer
up to ULLONG_MAX + 1 exactly, so it doesn't lose any precision
compared to long long. (It does compared to a bignum library, of
course.)
Many, but not all. It should be possible to determine whether a given
implementation does this using the constants in <limits.hand
<float.h(left as an exercise).

But be careful. If long double *doesn't* support the values you need,
it won't necessarily fail in an obvious manner; you'll just get
results that are *slightly* incorrect. Certain operations that are
specific to integers won't be available. And division works
differently; 3/2==1, but 3.0/2.0==1.5.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 11 '07 #7
On Tue, 11 Sep 2007 13:49:34 -0700, Keith Thompson wrote:
Army1987 <ar******@NOSPAM.itwrites:
>In many implementations long double is capable to hold any integer
up to ULLONG_MAX + 1 exactly
Many, but not all. It should be possible to determine whether a given
implementation does this using the constants in <limits.hand
<float.h(left as an exercise).
SYG_ENQVK / YQOY_RCFVYBA HYYBAT_ZNK, right?

--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 12 '07 #8
Army1987 <ar******@NOSPAM.itwrites:
On Tue, 11 Sep 2007 13:49:34 -0700, Keith Thompson wrote:
>Army1987 <ar******@NOSPAM.itwrites:
>>In many implementations long double is capable to hold any integer
up to ULLONG_MAX + 1 exactly
Many, but not all. It should be possible to determine whether a given
implementation does this using the constants in <limits.hand
<float.h(left as an exercise).

SYG_ENQVK / YQOY_RCFVYBA HYYBAT_ZNK, right?
Maybe. "Left as an exercise" didn't mean that I had figured it out
myself; I was just too lazy.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 12 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by dleecurt | last post: by
10 posts views Thread by Tuvas | last post: by
5 posts views Thread by soeren | last post: by
10 posts views Thread by Dave Cox | last post: by
23 posts views Thread by ultimatewarrior | last post: by
13 posts views Thread by Peter Oliphant | last post: by
26 posts views Thread by bilgekhan | last post: by
2 posts views Thread by WP | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.