A friend told me once that we are living in an Universe full of unprovable truths.

He was referring to the GĂ¶del's incompleteness theorems. Without being very formal, this says that there are many mathematical propositions that might be true but we cannot prove them using a computer program or any predictive way of checking, no matter how huge amount of time we can spend. We can find the proof for some, by luck, but for most of them we cannot find either a proof or disproof. In fact this "unprovable" propositions are way more many than the provable propositions. The provable propositions are like the set of natural numbers "N" and the unprovable propositions are like the set of real numbers (R).

## 2014-09-23

## 2014-09-19

### When float does not change when incrementing (C/C++ programming)

What would you expect if you increment 20 millions as float? Do you expect that it will not change at all?

Check the output of the simple program below. You may know the explanation, but did you expect it to happen to such relatively small values?

user@ubuntu$ gcc float_inc.c ; ./a.out

float has 32 bits

a=20000000.000000 a+1=20000000.000000

a=16777216.000000 a+1=16777216.000000

a=16777218.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777222.000000 a+1=16777224.000000

Check the output of the simple program below. You may know the explanation, but did you expect it to happen to such relatively small values?

**Output:**user@ubuntu$ gcc float_inc.c ; ./a.out

float has 32 bits

a=20000000.000000 a+1=20000000.000000

a=16777216.000000 a+1=16777216.000000

a=16777218.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777220.000000 a+1=16777220.000000

a=16777222.000000 a+1=16777224.000000

Subscribe to:
Posts (Atom)