[C++] very large integer values

Discussion in 'Programming/Html' started by asdfjkl, Mar 26, 2005.

  1. asdfjkl

    asdfjkl Member

    Messages:
    11
    Likes Received:
    0
    GPU:
    Club 3d gf fx 5900xt
    Is it possible to use large integer values like 10^20 in C++?
     
  2. stealthmaker

    stealthmaker Guest

    Messages:
    1,703
    Likes Received:
    0
    GPU:
    PowerColor ATI 5770 1GB
    i dont think so....
     
  3. MrRand0m

    MrRand0m Ancient Guru

    Messages:
    3,122
    Likes Received:
    0
    GPU:
    ATI 5850
    YES... you can use a long long - or an unsigned long long!

    A long long is like a long, cept longer!
     
  4. Elleomea

    Elleomea Master Guru

    Messages:
    416
    Likes Received:
    0
    GPU:
    Radeon Mobility 9000 (M9)
    an unsigned long long int would give you a 64bit number. That's only enough to store 10^19 not 10^20 (actual length is: 18446744073709551616 or 2^64)
     

  5. joblo_3

    joblo_3 Member

    Messages:
    17
    Likes Received:
    0
    GPU:
    GF4MX 440
    if you REALLY need VERY alrge numbers, there's a litte trick you could use....but still I find it weird that you need bigger then 64bits integers...maybe that if you explain a little more your problem, we could help better...

    hmm, how could I explain...

    Build an object that has a pointer to the last object created. Each object has a variable with 1 number in it. Auto-create has many objects as you need to get your very large number....though with this technique, you will need lots of memory and it will be slow to access...
     
  6. DPyro

    DPyro Master Guru

    Messages:
    202
    Likes Received:
    0
    GPU:
    Gigabyte 6600 GT
    or you could do a mantissa/sig fig thing...its a trick a lot of apps use (i know nvidia uses it for hdr) to get more value out of an int (or long) while sacrificing minimal accuracy.

    EX: first 5 bytes (bits?) represent the number, last 3 are the exponent. so 10010101 is 10010|101 is 18^5 is 1889568. Feel free to correct me if im wrong.
     
    Last edited: Mar 29, 2005
  7. stealthmaker

    stealthmaker Guest

    Messages:
    1,703
    Likes Received:
    0
    GPU:
    PowerColor ATI 5770 1GB
    you could probably program a way to use 2 sperate long values to gether to store large number....

    for example, varibles A and B, lets assume that each one takes 3 digits and u want to store a 6 digit number in them (123456), you could save 123 in variable A and 456 in variable B
     
  8. MrRand0m

    MrRand0m Ancient Guru

    Messages:
    3,122
    Likes Received:
    0
    GPU:
    ATI 5850
  9. dzutrinh

    dzutrinh Guest

    try the "__int64" type in Visual C++ 6.0.
     
  10. bakuryu

    bakuryu Ancient Guru

    Messages:
    3,270
    Likes Received:
    1
    GPU:
    XFX GeForce 6600LE @ 430/490
    Actually you can store that in long double
    That really would'nt be an integer but you can still get very accurate values.
    try printing it with:
    cout << setiosflags(ios::fixed) << 10^20 << endl;
     

  11. deathvirus

    deathvirus Ancient Guru

    Messages:
    4,507
    Likes Received:
    12
    GPU:
    RTX 2070 MaxQ 8GB
    Why dont anyone of you guys use linked lists ???? life is so much simpler with them !!!!
     
  12. bakuryu

    bakuryu Ancient Guru

    Messages:
    3,270
    Likes Received:
    1
    GPU:
    XFX GeForce 6600LE @ 430/490
    Absolutely!!!!
    I have a program that uses linked list to calculate factorials. Want to see factorial of 700 ??

    2422040124750272179867875093812352218590983385729207299450679664929938160215647420444519051666484819249321456671497049842327525093874817343838393757631459228450828499972271274140160311057830558463636337124079332447820739281101037112665387537180790257577919273108262916904750405235055060084012219492892375635136296622020023178109619818046179906897450420548912610870589088056503913584562211037693288782960900195074130999799035970711436279339094292032866260496375825461427727555710003007752906141470639574390024988514914264449865006458873226951941899545970333910351588559232940829569276986080222200289966128343931630028789203382654749603473516314765262772257171154686716862814184728741187147936349501653197457455660413134506049122044947052623384682088864790673309569292384215611788014274954905914148362303226200246816441301934846080254998647325270606104512088058712293349862185399243309054299576381718806247238195232604642614329894070636163753672091232751612378348273840757873567717532879242518337119540602943609411629349009566043720836737401090882392975031224612531245642687296717053747734506443314924558119560479901478736209556925161517737110399754730551854066328420014728657896286936523787080206476327157136441318773432751007263108056958251693811280957243202460157111778617472683761623869704457588005158037495665069625778930898095725794710701639238231528115579619120287378689238934335198508665933917257143975277707590597511989345068701735940169672561864713107115016747368992690116082633762172346688969840862517264384000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
     
  13. deathvirus

    deathvirus Ancient Guru

    Messages:
    4,507
    Likes Received:
    12
    GPU:
    RTX 2070 MaxQ 8GB
    Nice job bakuryu ... but what if the user wants to enter a number that's itself cant be defined using standard data types ???

    PS : the input could be the factorial of 700 !! whoa :D:p
     
    Last edited: May 4, 2005
  14. bakuryu

    bakuryu Ancient Guru

    Messages:
    3,270
    Likes Received:
    1
    GPU:
    XFX GeForce 6600LE @ 430/490
    See the code I have written can even find the factorial of factorial of 700. Only there will me insufficient memory!!

    And you wantto know how can take the input of lagre numbers.......... :p Won't be telling you but what you need is :-

    friend istream& operator >> (istream&,LinkedList& ) ;
    void addAtHead();
     
    Last edited: May 12, 2005
  15. deathvirus

    deathvirus Ancient Guru

    Messages:
    4,507
    Likes Received:
    12
    GPU:
    RTX 2070 MaxQ 8GB
    thanks for the reply ... thanks for getting back to the topic ..
     

Share This Page