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.
Printable View
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.
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 gothen long long....Code:long num
that's the simple answer.
>>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.
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 :)
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?
>>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.
no, it doesn't.Quote:
And does long long long long int really work?
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 isQuote:
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.
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.Code:0 to 4,294,967,295
thats in u.s. notation. :p
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.
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 :DQuote:
Originally Posted by Hunter2
>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.
so basicly the longest thing I can get is a long double int?
>>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"? :p
I think you leave out the int part. Though I believe technically you can leave it in. is that right prelude?Quote:
Originally Posted by Rune Hunter
>Though I believe technically you can leave it in.
Yes...if you discard everything past the decimal place. Integers and floating-point are different beasts fundamentally, even though you can use floating-point types to represent integral values with a little effort.
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
So I can get that many numbers crambed into the int? How big would the int be if they were all filled up?
Yes, you leave out the int part.
>>The largest possible standard built-in type in C++ is long double.
Ah. I was just about to post that "unsigned long long x;" gave me a compile error.
Apparently, on my C++ implementation/platform/whatever, long doubles are the same as doubles. Both are 8 bytes.
>>Though I believe technically you can leave it in.
Well, it won't compile on MSVC so I'm assuming that you can't (since MSVC tends to allow more than it disallows).
oh umm sorry I got this wrong. I want to use float. And float, I'm pretty sure, can handle decimal points. But I also heard they can be off when adding 2+2. I tried it and it was correct but so I could use a long double float?
And if a byte = 2 letters or numbers (or 1 of each) how can a long be 8 bytes and hold so much. Or are you talking about 8 bytes * the int. What the heck how does that work?
>So I can get that many numbers crambed into the int?
Only if by "int" you mean "several int manhandled to work together so that they look like one int". ;)
>Well, it won't compile on MSVC so I'm assuming that you can't
Whoops, I was thinking in abstract terms when the question was about type declarations. Silly me. :o
>>But I also heard they can be off when adding 2+2.
I certainly would hope that computers are smarter than that. Otherwise the world will be doomed when they take over.
>>a long double float
float and double are both floating-point values. double is twice the size of a float. You should realize that double is a built-in datatype just like int ;)
ok ok, all of these people posting at the same time is crazy but,
Now let me see if I got this...
double is a whole diferent type of varaible, right?
So then can it handle + and - and decimals?
and can I still put a long before it?
A byte is 8 bits. A bit is either 1 or 0. So with all possible bit combinations, that makes up to 256. A long has 4 bytes, therefore 4 * 8 = 32 bits -> 2^32 possible values. 8 bytes -> 8 * 8 = 64 bits -> 2^64 possible values.Quote:
And if a byte = 2 letters or numbers (or 1 of each) how can a long be 8 bytes and hold so much. Or are you talking about 8 bytes * the int. What the heck how does that work?
[edit]The 2 letters or numbers you're referring to is the hexadecimal representation. Hex is a base 16 number system, so you go 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,... It actually has 256 possibilities.
mmmm I get it now...
ok not really I will just live with that long number you gave before.
>double is a whole diferent type of varaible, right?
There are three floating-point types: float, double, and long double. You can think of them in similar terms as short, int, and long int, except for floating-point.
>So then can it handle + and - and decimals?
Yes, it's a numeric type, so naturally it supports the numeric operations.
>and can I still put a long before it?
Yes, but keep in mind that long double is technically a different type. C++ is picky about types matching up, and double is the default floating-point type.
>>double is a whole diferent type of varaible, right?
Yes.
>>So then can it handle + and - and decimals?
Yes.
>>and can I still put a long before it?
Yes. Except the additional 'long' isn't guaranteed to make it any bigger (as my quick test showed, with both double and long double being 8 bytes).
alright so a long double + double = messed up? So basicly I have to pick 1 type before I start making my program?
>>So basicly I have to pick 1 type before I start making my program?
Yes. ;)
If you're going to use built-in math functions, use double; if you're not, use long double if you're going to need all the storage you can possibly have.
>A byte is 8 bits.
Not necessarily, though octets (as they're called) are the most common by far.
>A long has 4 bytes
At least.
>alright so a long double + double = messed up?
No, because of type conversions, long double + double = long double. :)
alright thanks so much everyone!
I am going to start the program tonight.
(going to use dlls too :) )
NVM don't need that post.