>So where is the error in my analysis?
The part where you relied on undefined behavior to do something predictable. I can't figure out if you're really as dense as you seem, or just stubborn.
I understand you now. I took "undefined behavior" to mean the computation will return an arbitrary value, but that's not what you mean. I think this will fix it: replace y = x+1 by eiither y = double(x)+1 or y = 1.0*x + 1 or even y = x + 1.0
I ordinarily don't reply to snotty childish comments, but, wisely or not, I did this time.
K&R has a section on type conversions (Section 2.7). It seems to me that the stuff I've done is ok. Where is the UB?
Conversion of a double to an int when the value is outside the range of an int.
184.108.40.206 Real floating and integer
1 When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
The trouble here is that you keep trying to put 6 pounds of stuff into a 5-pound bag.