PDA

View Full Version : [SOLVED] smallest number allowed by my system



IAMTubby
October 4th, 2012, 11:51 AM
Hey,
I have a couple of questions

1)Is there any special variable assigned for the smallest and largest possible numbers allowed by my system ? like int.MinValue, int.MaxValue or something of that sort ?

2)Does it depend on my system alone or does it also depend on my version of gcc ?

Thanks

PS : I have a 64 bit system, running gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)
What's the smallest and largest numbers that I can get ?

IAMTubby
October 4th, 2012, 12:33 PM
Hey I did this :)


#include <stdio.h>
#include <math.h>

int main(void)
{
//printf("\nLargest possible number = %u",(unsigned int)((pow(2,(double)((sizeof(unsigned int)) * 8)))));
printf("\nLargest possible number = %d",(int)((pow(2,(double)((sizeof(unsigned int)) * 8)))));

return 0;
}

cipherboy_loc
October 4th, 2012, 12:49 PM
Define smallest for us? On the number line, a negative number would be the smallest, but you could be talking about number of decimal points of accuracy.

In 32 bits:
Largest unsigned int is (2^32)-1==4294967295
Smallest unsigned int is 0
Largest signed int is (2^31)-1==2147483647
Smallest signed int is -1*(2^31)=-2147483648

64 bits, just change the math to 64/63 from 32 and 31 respectively.


Thanks,
Cipherboy

IAMTubby
October 4th, 2012, 01:10 PM
Define smallest for us? On the number line, a negative number would be the smallest, but you could be talking about number of decimal points of accuracy.

In 32 bits:
Largest unsigned int is (2^32)-1==4294967295
Smallest unsigned int is 0
Largest signed int is (2^31)-1==2147483647
Smallest signed int is -1*(2^31)=-2147483648

64 bits, just change the math to 64/63 from 32 and 31 respectively.


Thanks,
Cipherboy
Thanks Cipherboy :)

Tony Flury
October 4th, 2012, 02:12 PM
in C there are macros defined for these limits :

http://en.wikipedia.org/wiki/C_data_types#Interface_to_the_properties_of_the_ba sic_types