Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`
steve+comp.lang.python at pearwood.info
Thu Sep 18 05:11:53 CEST 2014
> Chris, why is this invariant `div*y + mod == x` so important? Maybe it's
> more important to return a mathematically reasonable result for the the
> floor-division result than to maintain this invariant?
You keep talking about floor(inf) == inf being "mathematically reasonable",
but I'm not convinced that it is. Can you justify why you think it is
mathematically reasonable? Remember that IEEE-754 inf represents two
(1) A large but finite number which has overflowed.
(2) Actual mathematical infinity ∞.
Even in the case of actual mathematical infinity, the result of floor(∞)
isn't clear to me. Floor is supposed to return an integer, how do you know
that ∞ is integer valued? You can do ∞ % 1 to see what the fractional part
is, but that gives NaN, so justify your belief that ∞ is integer-valued.
 But *which* mathematical infinity? One of the cardinal infinities, the
alephs, or one of the ordinal infinities, the omegas and the epsilons?
(There are an infinite number of *all three*.) Is c just another name for
aleph-1, or is distinct from all the alephs? Even professional
mathematicians tread warily when doing arithmetic on infinities.
More information about the Python-list