0
issue with yield
I wrote his code: def count(): i=10.4 while i>0: yield i i-=1 for i in count(): print(i) the output I got was: 10.4 9.4 8.4 7.4 6.4 5.4 4.4 3.4000000000000004 2.4000000000000004 1.4000000000000004 0.40000000000000036 can someone explain why the difference between values changes to something else then 1.0 after a certain point? I tried with different examples, like 8.7 or 14.3 and it's the same. it doesn't happen though if the float ends with 0 or 5, for example 6.5 or 20.0. neither does it happen when I write i+=I, only when it goes from bigger to smaller value.
1 ответ
+ 3
Issue is not with yeild. It with floating point values.. It's because of compiler internal operations with float values..