> > 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.
Since you know the bit pattern that would yield the value, just make an union with an uint64_t and a double, set the uint to the desired bit-pattern, and printf the double: #include <stdint.h> #include <stdio.h> int main(void) { union intdouble { uint64_t foo; double bar; } maxdouble; maxdouble.foo = 0x7FEFFFFFFFFFFFFF; printf("%lf\n", maxdouble.bar); return 0; } > > > > 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) It depends on the exponent. If the exponent is large (as above), you won't get anything after the decimal point. The maximum you can get after the decimal point is when you have a denormalized number (exponent all-zeroes) and a mantissa of 000...1. That will give an exponent of -1022 and a significant of 2^(-52), yielding a value of 2^(-52)*2^(-1022) = 2^(-1074), roughly 10^(-324). > Doesn't matter if it's unsigned or signed , some ideas are cool enough. IEEE floating-point numbers are always signed. Firas