473,796 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Large number in C

KC
How can I represent a 22-digit integer in C? float is not large enough.

Thanks!
Nov 14 '05 #1
4 1656
begin followup to KC:
How can I represent a 22-digit integer in C?
Is that 22 digits in decimal radix?

$ echo 'scale=3; l(10)/l(2)*22' | bc -ql
73.062

Requires significantly more than 64 bits so 'long long' does not help.
float is not large enough.


float is typically 32 bits for both mantissa and exponent giving
about 7 decimal digits. double extends that to about 15.
The built-in data types of C are not enough for your problem.

http://www.swox.com/gmp/

--
Für Google, Tux und GPL!
Nov 14 '05 #2
On 17 Apr 2004 06:44:31 -0700, mr*****@yahoo.c om.hk (KC) wrote:
How can I represent a 22-digit integer in C? float is not large enough.


Standard C does not have a type guaranteed to satisfy you on all
conforming implementations .

It is possible that you could find an implementation that runs on
your system with 128 bit long long that would work.

More likely, you can use one of the numerous "bignum"
implementations which use only standard features and are therefore
extremely portable. I have played with CLINT from Richard Heathfield
at www.rjgh.co.uk. It is free and I think it will do what you want.
<<Remove the del for email>>
Nov 14 '05 #3
KC wrote:
How can I represent a 22-digit integer in C? float is not large enough.


Since the range of 22-digit integers in approximately pow(2,69.8) to
pow(2,73.1), find an implementation that has a type with 70+ bits to
represent *some* 22-digit integers, or 74+ bits to represent *all* the
22-digit integers.

You could join together two or more shorter integer types in a struct,
or, if you don't want to do that, find a free open-source bignum library
on the web. There are some googlehints in that last clause.
Nov 14 '05 #4
You can -

Try a linked list implementation, with possibly a long integer as a
member, if you want to learn. It would be fun.
- Or -
Use any of the suggested libraries in the prev. replies if you want the
job done right away.

All the best.

KC wrote:
How can I represent a 22-digit integer in C? float is not large enough.

Thanks!


--

--
Rakesh Kumar
** Remove nospamplz from my email address for my real email **
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
6406
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
1
2915
by: DJTB | last post by:
zodb-dev@zope.org] Hi, I'm having problems storing large amounts of objects in a ZODB. After committing changes to the database, elements are not cleared from memory. Since the number of objects I'd like to store in the ZODB is too large to fit in RAM, my program gets killed with signal 11 or signal 9... Below a minimal working (or actually: it doesn't work because of memory
2
6824
by: Kevin Crosbie | last post by:
Hi all, (Sorry for the cross-post, there doesn't appear to be much activity on comp.database.oracle)I'm trying to get the last 300 rows from the difference between 2 large tables and my queries are taking at least 10 minutes to do this. I'm running on quite a fast server and the tables are not very large, 3,000,000 to 30,000,000 rows. I've tried the following:
24
4046
by: Salad | last post by:
Every now and then I see ads that state something like "Experience with Large Databases ...multi-gig...blah-de-blah" And I have to laugh. What's the difference between a large or small database? A table is a table, a record is a record, a field is a field. All you are doing is manipulating data in tables. I wouldn't think it'd make much difference in working with a table with 10 records or a billion records...they're nothing more than...
18
5643
by: Zero | last post by:
Hi, I am calculating an integer to the pwer of a large integer, e.g. 2^5000. It turns out that the result I always get is zero. I am sure that the result is too large to store in such type as u_int64_t and long int etc. My power function is as follows: for(i=0; i<5000; i++) result *= 2;
5
5610
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that uses very high volume DB transactions - in the order of tens of millions per day . . . Anyway, the current database which will remain nameless, but begins with O and rymes with debacle (sorta), has a problem with high volume work when it comes to...
22
4505
by: Frinton | last post by:
Hi, I am trying to do some calculations on large numbers (ie 7,768,489,957,892,578,474,792,094 / 12,280) and no matter what I do it doesn't get it quite right. Its always somewhere between 10 and and 5000 out :( I have a suspition is could be down to one of the number functions I am using along the way but im not sure.
8
6395
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am looking for. My problem is that i have to upload images and store them. I am using filesystem for that. setup is something like this, their will be items/groups/user each can
0
22480
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with a normal integer. I needed this in a C++ program running on a 32-bit UNIX platform. The problem was that the number was 28 digits long and no native datatype in c++ could store a number of that size. (Eg: 1088263455689473669888943602 % 380) Not...
12
3715
by: fermineutron | last post by:
I am trying to write a function which will convert a large ascii number, say 100 ascii digits, to its binary representation. It seems that evey algorithm I am trying to think of is backwards. Normaly in pen and paper ascii to binary conversion one would start by subtracting largest power of 2 that can be subtracted from the given number and work from left to right filling memory up with 1s and 0s. In my case I cant really do that b/c the...
0
9680
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.