Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

elis-cool

Can you hold a larger value int or float?

This topic is 5975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this has probly been asked before but an int only being able to hold around 2 billion is just not good enough for some applications but you can use an unsigned int, then theres a long which is exaclty the same as an int these take up 4 bytes but is there away to make it so an int can hold like 284298473034572457020943503 which is a hell of a lot more than a normal int can hold. I think I may have breifly saw something about increasing the number of bytes a variable uses. Is this advanced? Could some one tell me how it is done or point me to a site?

Share this post


Link to post
Share on other sites
Advertisement
Many compilers have support for "longer than long" integers. The C99 standard calls for a "long long" integer type to do this (which should become 64bits in most 32bit C99 compliant compilers). MSVC has the non-standard __int64 type that you can use. An unsigned 64 bit integer can hold up to 264 .

Floats can hold up to 3.40282*1038 and as low as 1.17549*10-38 on x86 platforms. You shouldn't have a problem with them. But, if you do, use "double" instead of float. Some compilers have a "long double" as well.



Edited by - Null and Void on February 5, 2002 5:06:03 PM

Share this post


Link to post
Share on other sites
float can hold larger numbers. but it will be an approximation.

you might also want to use "__int64".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
I know that floats can only hold 6 decimal places and doubles 15 then after that they get rounded off to zeros after those 6, 15 places have been filled with a proper number, eg a float could hold 2.22222 or something but 2.2222222222222222222 would be rouded off to something like 2.2222200000000000000.
So how many would a __int64 hold and how many would a long double hold?
Is this correct?
    
__int64 var = 5;
long double var2 = 3.14;


Edit: Typo

Edited by - elis-cool on February 5, 2002 5:19:26 PM

Share this post


Link to post
Share on other sites
__int8, __int16, __int32, __int64 are supported by g++, borland, and msvc, so even if they''re nonstandard, they''re pretty safe to use.

Also, you might want to have a look at this.

Share this post


Link to post
Share on other sites
quote:
Original post by elis-cool
So how many would a __int64 hold and how many would a long double hold?


I already told you that an unsigned 64 bit integer can hold up to 264 (i.e. 1.8446744074*1019). The bit count of a long double changes depending upon the compiler and platform. In x86 GCC it is 96 bits (a normal double is 64 bits). I don''t know the exact limits of that or the precision, but I''m sure you can find out with a little searching.

Share this post


Link to post
Share on other sites
quote:

__int8, __int16, __int32, __int64 are supported by g++, borland, and msvc, so even if they''re nonstandard, they''re pretty safe to use



You should wrap any non standard types in a typedef so that if you change platforms or compilers later, it will be easier to update your code.

Share this post


Link to post
Share on other sites
What language are you using? Perl has support for arbitrarily large integers.

If __int64 isn''t big enough for your data... I would guess you need to reasses your design, there is something wrong! What are you using this for?

Share this post


Link to post
Share on other sites
The x86 native architecture has inherit support for unlimited length integers. You just have to write asm to handle the overflow conditions. 32bit additions will set the carry flag if they overflow (then you can inc the next int in ram). There''s a 32bit multiplication that returns a 64bit value, so you can detect and handle overflow there as well.
(And I think the execution speed would beat the living daylights out of Perl )

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!