Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`
steve+comp.lang.python at pearwood.info
Thu Sep 18 04:50:53 CEST 2014
Chris Angelico wrote:
> On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>> Invariant: div*y + mod == x.
>>> If mod is NaN, there is no possible value for div that will make the
>>> invariant true, ergo it too has to be NaN.
>> That still doesn't make the invariant true. By this argument div could
>> be 42, and the invariant would hold equally well (i.e. not at all).
> Nothing can possibly make it true, so there are only two
> possibilities: return NaN, or raise an exception.
If nothing can make it true, then it is not an invariant, and your argument
is no longer valid.
More information about the Python-list