Thread: How do you store very large numbers in standard form?

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    How do you store very large numbers in standard form?

    I have tried using doubles and floats, but with no success. What data type would you use if you wanted to store a large number in standard form? The number I want to store is 2m/(hbar^2) which is roughly 1.636*10^38. Do I need to use a mathematics lib like gmp in order to do it?


  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That should work just fine in a "double", as double supports about 1e308.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    This worked fine for me:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        
        double large;
        scanf("%lf", &large);
        printf("%g\n", large);
        return 0;
    }
    Code:
    C:\Documents and Settings\Andrew Feist\Desktop>temp
    1.636e38
    1.636e+038

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Do I need to use a mathematics lib like gmp in order to do it?
    That depends on whether you need the absolute accuracy offered by GMP, or the relatively accurate approximations offered by the floating point formats.

    For example, if you're trying to do crypto with large prime numbers, then you definitely need GMP.

    "There's safety in numbers, large prime numbers!".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Large numbers
    By password in forum C++ Programming
    Replies: 9
    Last Post: 06-28-2007, 02:15 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Very large floating point numbers
    By bulsquare in forum C Programming
    Replies: 0
    Last Post: 04-08-2002, 04:10 PM
  4. printing large decimal numbers
    By Isometric in forum C++ Programming
    Replies: 5
    Last Post: 03-20-2002, 09:55 PM
  5. commas in large numbers
    By HKR in forum C Programming
    Replies: 7
    Last Post: 03-06-2002, 07:08 PM