-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/18/2010 06:56 PM, Firas Kraiem wrote: > On 18/07/2010 12:27, Aaron Lewis wrote: >> Hi, >> how can i determine the maximum size of `double' without printing out >> DOUBLE_MAX ? >> >> And what about the precision of a `double' , anyone give a try ? >> >> Google ain't giving much information , i just can't figure out , it's >> very funny coding , isn't it ? >> > > Kinda off-topic for here but whatever...
Yeah , i'll put a OT here. > > Assuming 64-bit double, it has a mantissa of 52 bits and an exponent of > 11 bits. If the mantissa is all-ones, that will give a significant of > 2-2^(-52). The exponent cannot be all-ones (an all-ones exponent means > infinity or NaN), so the largest exponent is 2^11-2 = 2046, minus bias > (1023), it gives a maximum effective exponent of 1023, so that would > give a value of (2-2^(-52))*2^(1023) = 2^1024 - 2^971, roughly 10^308. Yep , right , but how you *get* it by a beautiful code , that could be really interesting. I mean , with a small code , c or c++ , printing the size out. > > What do you mean by "precision"? Kinda of significance digit. For example: A number `12.340' , and if say it has 2 digits' precision , then we consider the `0' is not accurate , while `.34' is accurate. So for a number stored in a double type , how accurate can it be ? (or maybe how many bits in the fixed-point part is accurate) Doesn't matter if it's unsigned or signed , some ideas are cool enough. Still , use a small part of code , c or c++ , i'm just curious how to make it happen. > > Firas - -- Best Regards, Aaron Lewis - PGP: 0x4A6D32A0 FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0 irc: A4r0n on freenode Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxC4IkACgkQvf41sEptMqBN3wCeNNWj/cs9b1SB4hXwxqnJQrR4 gxsAoLKTzixeHSQzWHAeKTzgp6WDPn3I =McSS -----END PGP SIGNATURE-----