473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 14583
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: dleecurt | last post by:
Hello, I have a small problem, I am trying to write a program that will calculate the Fibonacci number series, and I have the code complete with one problem. I used a long in to store the numbers,...
10
by: Tuvas | last post by:
I've been thinking about writing a program to generate the world's largest prime numbers, just for the fun of it. This would require being able to hold an 8000000 digit number into memory (25...
5
by: soeren | last post by:
Hello, two days ago I stumbled across a very strange problem that came up when we were printing tiny double numbers as strings and trying to read them on another place. This is part of an object...
10
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
6
by: 05l8kr | last post by:
I'm suppose to edit the function called swap_values so that it receives three numbers (not two nubmers) called first , second, and third. These numbers will not be in any special order (for example...
3
by: Rahul | last post by:
Hi, Is there a way to get the line numbers to display in the exception when you have published your web site? Thanks Rahul
23
by: ultimatewarrior | last post by:
Hi all, first of all I beg your pardon if this question has been asked before, but I was unable to find anything in the past posts. I have written a piece of code that was supposed to be quite...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
2
by: WP | last post by:
Hello, below is my very first python program. I have some questions regarding it and would like comments in general. I won't be able to get my hands on a good python book until tomorrow at the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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 projectplanning, coding, testing,...

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.