Thread: Range of data types in C..

  1. #1
    Registered User
    Join Date
    Jan 2012
    Location
    Chennai, Tamil nadu, India
    Posts
    30

    Exclamation Range of data types in C..

    Hello friends.., I need to process a very big, say a 16 digit number.. For example, i need to multiply 2 to 421052631578948368.. But i'm totally puzzled... Which data type is apt for storing and manipulating it...? Or is there any need for using "dynamic memory allocation"..?Please help me to solve this situation friends..

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    The operation you said would still technically still fit in an unsigned long long type (uint64_t).

    However, it's relatively close to the limit, and if you need numbers over 18446744073709551615 (assuming 64-bit architecture), you'll need a big-number library.

    Dynamic memory allocation won't really do you any good unless you want to pack the numbers and re-write practically everything, but in that case, that's what a big-number library will do for you.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Location
    Chennai, Tamil nadu, India
    Posts
    30

    Arrow @memcpy,,

    So, you mean, that there is a new datatype that has more range... isn't it..?

    If so, then how can we use that..? what's it syntax & its format specifier...?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    long long and unsigned long long. As for the format specifier for the printf family of functions, that would be %lld and %llu respectively, though you may need to use %I64d and %I64u instead on Windows.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jan 2012
    Location
    Chennai, Tamil nadu, India
    Posts
    30
    Well, are you saying it by your own guess..?

    It's not working on windows... I used all the format specifiers you mentioned...

    I have code::blocks compiler...Is there any modifications i need to do there..?
    Also, please mention the range of that data type and it's exact format specifer...

    Thanks..!!

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    laserlight is not guessing. The maximum value that can be represented by an unsigned long long is guaranteed by the 1999 C standard to be at least 18446744073709551615, which exceeds the value you want to double (421052631578948368) by about 40 times.

    Not all compilers support a long long types though. mingw (the compiler suite used by code::blocks) does, although you may need to configure it (project settings or command line options for the compiler) to support the 1999 C standard (the 1989 C standard and the C++ standard do not support long long types).

    Given that you are providing minimal information, getting snippy - as you are - when advice does not work out exhibits a rather ........ty attitude on your part.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Rehman khan View Post
    I have code::blocks compiler
    Code::Blocks is an IDE; not a Compiler.
    Learn the name and version of your Compiler!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    Jan 2012
    Location
    Chennai, Tamil nadu, India
    Posts
    30

    Arrow @stahta01

    Yeah... It's correct.. i remember... So, i'm using Code::Blocks IDE, in that, GCC compiler... Now, can you explain how can i implement that datatype "uint64_t" in this compiler..? Will this GCC compiler supports "long long" & "unsigned long long" type..? If so, please mention how can i use this...? is it similar to "long" in usage..? Thanks...!

  9. #9
    Registered User DevoAjit's Avatar
    Join Date
    Jun 2011
    Location
    Ludhiana, Punjab, India, India
    Posts
    32
    Sir, can u tell me "is code::block can be used for compiling c program"

  10. #10
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by DevoAjit View Post
    Sir, can u tell me "is code::block can be used for compiling c program"
    Yes, it can. It brings along MinGW with GCC, and all you have to do is make a project, create and fill a file and click the compile button.
    Devoted my life to programming...

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: Code::Blocks IS NOT a Compiler!!

    Under Windows, Code::Blocks is sometimes packaged with the MinGW GCC Compiler.
    It IS NOT always packaged with the MinGW Compiler or any other Compiler.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  12. #12
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    If you're using GCC, try using a long long long

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-04-2010, 01:34 AM
  2. Data Types
    By kas2002 in forum C Programming
    Replies: 1
    Last Post: 05-21-2009, 07:30 AM
  3. Replies: 2
    Last Post: 01-31-2008, 09:52 AM
  4. data types types...
    By gftmc in forum C++ Programming
    Replies: 3
    Last Post: 09-11-2006, 11:30 AM
  5. data types help
    By Bud in forum C Programming
    Replies: 2
    Last Post: 06-27-2002, 12:35 PM

Tags for this Thread