LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-21-2009, 05:56 PM   #1
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 896

Rep: Reputation: 70
Handling very large integers in C: which data type?


Hi all

I've reached a point in this program I'm writing where I need to deal with an integer that's unusually large: 1.8x10^19. I can't find any data type capable of handling more than a couple of gig. What can I use that will handle it and what is the corresponding printf format (%d% %lf% etc.)?

Thanks!
 
Old 10-21-2009, 06:08 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You can use long long int and unsigned long long int for integers of at least 64 bits, though I should note that the value you are dealing with is the maximum 64 bit unsigned value.

These can be printed using '%lld' and '%llu'.

If you need longer integers than 64 bits, you should look at using an arbitrary precision maths library.

Last edited by neonsignal; 10-21-2009 at 06:12 PM.
 
Old 10-21-2009, 06:14 PM   #3
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 896

Original Poster
Rep: Reputation: 70
Thumbs up

[QUOTE=neonsignal;3727797]You can use long long int and unsigned long long int for integers of at least 64 bits, though I should note that the value you are dealing with is the maximum 64 bit unsigned value.

These can be printed using '%lld' and '%llu'.

Hey thanks, buddy.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cifs and 426 Sendfile error: Value too large for defined data type punt Linux - Networking 5 04-10-2008 05:59 AM
Porting an embedded app to Linux, handling persistent data AAD Programming 1 12-11-2007 10:28 PM
make bzImage failure - "Value too large for defined data type" hce_ Linux - Kernel 2 07-01-2007 02:30 PM
Filesystem Type for large network storage smudge|lala Linux - General 2 01-18-2007 11:22 AM
Large data files on CD dema Linux - Newbie 1 01-26-2002 10:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration