Big (and small) numbers...

This is a discussion on Big (and small) numbers... within the C Programming forums, part of the General Programming Boards category; I have quite a few questions regarding variables in C, and their supported sizes. Firstly, I need to be able ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Question Big (and small) numbers...

    I have quite a few questions regarding variables in C, and their supported sizes. Firstly, I need to be able to hold a number (as large as) 9999999999 in a variable. I'm not sure which type to use (I've been told float or double can do the job)... Which would any of you recommend for this?

    Also, I would like to have support for significant digits after a decimal point of up to 1 million. I'm not sure how far a double or long double supports in the negative region, but I would obviously need a range (at least) like this: 10^1000000 to 10^-1000000. Is this possible, and if, with what variable type?

    Lastly, I am curious to know why when I use a float or a double (especially), when I use printf to print the variable, no matter how long (after the decimal) I declare it, it will only show 6 significant digits (Including numbers before the decimal). For instance, if I declare something to be 1.2345678, when using printf() to print the variable, I only get 1.23456. Similarly, if I declare a variable to be .12345678, I only get .123456. Do I need to declare the number of spaces after the decimal point to get this to work? (i.e.
    Code:
    printf("%.10f\n", var);
    Any responses would be GREATLY appreciated!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) long long int (if your compiler supports it).
    2) You'll have to write your own. Nothing will give you that precision, especially since floating point numbers in C are not precise.
    3) When you write your own data type for your huge floating point numbers, you can go ahead and write your own input and output functions for it as well.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    26
    Just out of curiousity, why do you need that kind of percision?

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Smile precision necessary because....

    I'm finding the first ten digit prime in consecutive digits. I want to make sure my number is exact because the function i wrote in e limits the amount of sig. digits in the loop.

    if i calculate to 1000000 sig. digits, i dont' need to worry about the first 100000-200000 being inaccurate.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    38
    You might want to google on existing high-performance libraries. I've heard a great deal of "GMP" and "Miracl". Not sure if they are pure C though...

  6. #6
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Answer to question 1:
    __int64 would probably achieve this. It can store up to 18,446,744,073,709,551,615.

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Thanks

    Just wanted to thank everyone for their assistance... your ideas have furthered possibilities for me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small program big problem :-(
    By Fibre Optic in forum C++ Programming
    Replies: 4
    Last Post: 09-20-2005, 09:53 AM
  2. Big Letter became small letter
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-13-2004, 02:04 PM
  3. Small Problem that could be a big problem
    By sytaylor in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2004, 10:49 AM
  4. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 04:23 AM
  5. Big and Small
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2002, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21