473,549 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14586
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.c omwrites:
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[] = "32345678903234 567890323456789 0";

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******@NOSPA M.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_Keit h) 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******@NOSPA M.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******@NOSPA M.itwrites:
On Tue, 11 Sep 2007 13:49:34 -0700, Keith Thompson wrote:
>Army1987 <ar******@NOSPA M.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
implementati on does this using the constants in <limits.hand
<float.h(lef t 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_Keit h) 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
13092
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, and when the numbers get too large it maxes out the int and I can't count any higher. I am trying to use extremely large numbers, I would like to...
10
4972
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 megabits, or a little over 3 megs of memory for just one variable...) I would also need several smaller variables. This came about as I optimised a prime...
5
4057
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 serialisation framework that cannot be done in binary format currently, so please no comments about this ,-)) It took quite some time to shrink...
10
1826
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
6
2019
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 enter 20.0, 3.1 and 9.3). The function swap-values will need to be edited to use more "if" statements to place the smallest vlaue in the variable named...
3
1754
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
638
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 portable, and uses a lot fp numbers. Everything goes well on PPC cpus, but on some x86 CPU I get a dramatic loss of performance. After some...
13
2780
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, or between 0 and 99999 (inclusive). Further, the I want the range to be a variable. Concretely, I would like to create the following method: ...
26
7880
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()); int r2 = rand(); bool f = r1 == r2;
2
1399
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 earliest. The program takes a string and sums all numbers inside it. I'm testing with the following string: "123xx,22! p1" which should yield a sum of...
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7960
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
7812
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
6048
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5089
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
3501
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
1944
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
1061
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.