Thread: varaible help...?

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    varaible help...?

    So I know there is a limit on how long an int varaible can be. Soooo....


    Is there a way to make that inf. or at least very very close to inf.?


    besides the long int way.

  2. #2
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    infinity like more than the amount of space you have on your hard drive.
    Think of this way once you've reached the max amount a data type holds you go up to the next. So yeah you'll have to go
    Code:
    long num
    then long long....
    that's the simple answer.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Is there a way to make that inf. or at least very very close to inf.?
    Depends on what you mean. If you mean extending the built-in datatype, then no unless you want to rewrite your compiler (and then it won't be standard). You can create a class which has the same functionality as an int though, and manually does bit operations on a 2gb char array (dynamically created of course) if you really want. That will get you as close to infinity as you're going to get (2gb will get you an astronomically huge number, assuming you have that much RAM on your computer). In fact, if you want, you can make a datatype of 80gb or more if you store the number in a file. Alternately, and less efficiently, you could do save the number as a string and manually perform operations on the individual digits. However, you'll have trouble using it in conjunction with any functions that use normal datatypes, unless you supply conversion operators which truncate or wrap the number when it's too large, and then return the result.

    Why do you need a super large int anyway? Usually an unsigned long or double will be plenty for any real-world applications.

    **EDIT**
    long int is the same as int, for most cases.

    >>then long long....
    I don't think that's a standard type, although the Windows API has a LONG_LONG struct or something that it uses in some of its more precision-demanding functions.
    Last edited by Hunter2; 09-13-2004 at 06:13 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    no, you cant make a variable go up to infinity. An integer size is defined by your compiler, and you cant change its size. If you are using windows, you can use the LARGE_INTEGER type which is 64 bits wide. This doesn't reach infinity, but it gets pretty high

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    no reason yet. I just want a big number. Becuase when you multiply 2 big numbers you get a small. And does long long long long int really work?

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>does long long long long int really work?
    We all wish it did.

    >>Becuase when you multiply 2 big numbers you get a small.
    Generally you don't run into this problem unless dealing with crazy math formulas. Even then, if you don't mind losing precision then you can round/truncate it to 5+ significant figures or so and then use scientific notation (doubles do this I think). Even the number of milliseconds a computer has been running can be stored in an unsigned long for several years running.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    And does long long long long int really work?
    no, it doesn't.

  8. #8
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    I don't think that's a standard type, although the Windows API has a LONG_LONG struct or something that it uses in some of its more precision-demanding functions.
    Perhaps it isn't at that. He is after all speaking of C++. However in C that is a valid data type. It is intended to support 64 bit integers now that 64 bit processors are coming. for unsigned long its minimun range is
    Code:
    0  to 4,294,967,295
    for unsigned long long it is 18 quintillion, four hundred and forty-six quadrillion,seven hundred forty-four trillion,seventy three billion,seven hundred nine million, five hundred fifty-one thousand, six hundred and fifteen.
    thats in u.s. notation.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    lol you hit the spot. I am making a computer program to help me and others do math probeblems. And once I take algebra I might get those crazy math probebelems for extra credit or somtin.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I'll have to try that out, I've never heard of long long's before... only doubles.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #11
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Hunter2
    I'll have to try that out, I've never heard of long long's before... only doubles.
    doubles come a little after. Then if your man enough you can hit long doubles. but C only gurantees its percision is at least as percise as double
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I've never heard of long long's before... only doubles.
    long long is an extension except in C99. The largest possible standard built-in type in C++ is long double.
    My best code is written with the delete key.

  13. #13
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    so basicly the longest thing I can get is a long double int?

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Then if your man enough you can hit long doubles.
    long doubles... 16 bytes/128 bits?

    >>but C only gurantees its percision is at least as percise as double
    Precision as in significant figures as opposed to magnitude? That would mean... 8 bytes to hold the sign bit and exponent. And if you consider it, that means the exponent can go up to "18 quintillion, four hundred and forty-six quadrillion,seven hundred forty-four trillion,seventy three billion,seven hundred nine million, five hundred fifty-one thousand, six hundred and fifteen"?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #15
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Rune Hunter
    so basicly the longest thing I can get is a long double int?
    I think you leave out the int part. Though I believe technically you can leave it in. is that right prelude?
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-22-2002, 10:02 PM
  2. function return varaible
    By Kohatian 3279 in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2002, 10:51 PM
  3. varaible trouble
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 03-15-2002, 08:03 AM