Integer division

This is a really good question!

I think what’s going on is that when 0.4 is converted to binary floating point, you get a value a tiny bit bigger than 0.4:

In [40]: f"{0.4:.40f}"
Out[40]: '0.4000000000000000222044604925031308084726'

So 6 / 0.4 is a tiny bit smaller than 15.0, and thus gets truncated to 14.0

However, (and now I’m out of my depth with FP) – when you actually compute 6 / 0.4, you do get 15.0 (which is exactly representable in binary) as far as I can tell:

In [43]: f"{6 / 0.4:.60f}"
Out[43]: '15.000000000000000000000000000000000000000000000000000000000000'

So I don’t get why the rounding doesn’t occur the same way before the truncation.

I’m sure someone that gets FP better than I do can explain …

-CHB