2

I am dealing with very large numbers in my C++ application which can exceed 64bit variables and when look at:

qDebug("lowest: %f", std::numeric_limits<double>::lowest());
qDebug("max: %f", std::numeric_limits<double>::max()); 

the output is:

lowest: -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000
max: 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000

This makes me conclude that the data type double can be 2048bits in size. However, I have never heard that there are variables which are larger than 64bit in size on standard machines.

There must be something wrong in my assumption. Could anyone give me an explanation? (Also, I am using the QT Framework and OpenCv in my application if that matters. )

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
dcfyg
  • 75
  • 9
  • 2
    You have to understand how doubles are encoded to answer your own question: https://en.wikipedia.org/wiki/Double-precision_floating-point_format – The Quantum Physicist Feb 28 '17 at 12:17
  • 1
    Does [this](https://stackoverflow.com/questions/7644699/how-are-floating-point-numbers-are-stored-in-memory) help? Potential duplicate. – Baum mit Augen Feb 28 '17 at 12:22
  • Found a better one. :) – Baum mit Augen Feb 28 '17 at 12:24
  • So basically a double is represented like the scientific notation with the difference that the base is 2 instead of 10 and there are some special cases. What I dont understand is this: Wikipedia states "The 11 bit width of the exponent allows the representation of numbers between 10^−308 and 10^308, with full 15–17 decimal digits precision." . Does that mean there can be 10^616 unique states? I would think that "std::numeric_limits::max() " should output me a 15-17 digits with 291-293(308- 15 or 17) following zeros. But in my case it printed 308 (mostly) non-zero digits. – dcfyg Feb 28 '17 at 13:05
  • Most digits being 0 in base 2 does not mean that most digits are 0 in base 10. If you need a more detailed explanation, please ask a new question. – Baum mit Augen Feb 28 '17 at 13:51
  • Here is an example. Lets assume I want to store the number 1.11111... * 10^300 (= 301 consecutive '1's). If I try that with a 64-bit double it will turn out to be printed as: "1111111111111111100000000...0" (= 17 '1's following only '0's) since the double can only store up to 17 decimal digits and the exponent. Or to put it in a different way: The bit sequence of the number "1111...1" (=301 consecutive '1's) and the number "11111111111111111000...0" (= 17 '1's following 284 '0's) stored in 64-bit double variables will be exactly equal. Is that correct? Sorry, if I am not clear enough. – dcfyg Feb 28 '17 at 14:23

0 Answers0