I am working on a research project about integer values. Incrementing them above range, and then decrementing them below range. I've got the basic concepts with int, short int, and long int. But when it comes to float and double I am unsure exactly what is going on. So here is my test code and then the result:
The results for the max value return the initial value, whilst the min value returns a -1. I would really appreciate if someone can help me understand the data flow better.
Try to answer these questions and it should lead you to an understanding of floating point.
1. Though a variable of type long long and a variable of type double take up the same amount of memory, the range of a double is (much) larger than that of a long long. How would this be possible?
2. Though 1.0e+20 is much smaller than the maximum value of a double, why is 1.0e+20 + 1 equal to 1.0e+20?
Does your answer to question 1 suggest anything?
Working with other classmates today we are all very stumped by the result when we increment beyond the max range of double and float. And then the result for double and float being decremented below the minimum. We were talking if it had anything to do with their values being true for infinity.
But considering the result for max float and double incremented above range produced the same number (1e38 for example), while the minimum float and double decremented below range produced a -1. This is the big hangup. I could see how incrementing above the range for double and float would possibly stay in the range of infinity, but why would the decrement below range produce a -1?
1. How many distinct values can 64-bits in memory hold?
2. How many real numbers are there between 1 and 10^20? Betweeen 1 and 2?
3. Does the term 'The Pigeon Hole Principle' ring a bell?
4. We have initialised e this way constdouble e = 0.01 ;. Then why is it printed as 0.01000000000000000021?
5. In 1000000000000.00000000000000000000 + 0.01000000000000000021 == 1000000000000.01000976562500000000,
where have the digits 9765625 come from? What happened to the 21 at the end?
6. Why is 10000000000000000000000 multiplied by 10 yielding 999999999999999983222784?
7. Why are 10000000000000000 + 3, 10000000000000000 + 4 and 10000000000000000 + 5
all giving the same result 10000000000000004 ?