When is divmod(a,b) == floor(a/b)-1 ?
robert.kern at gmail.com
Thu Sep 24 22:55:00 CEST 2009
On 2009-09-24 14:40 PM, kj wrote:
> The docs for divmod include the following:
> divmod(a, b)
> ...For floating point numbers the result is (q, a % b), where q
> is usually math.floor(a / b) but may be 1 less than that. ...
> I know that floating point math can sometimes produce "unexpected"
> results, so the above caveat is not entirely surprising. Still,
> I would find it helpful to see a specific example where
> divmod(a, b) is equal to math.floor(a/b)-1. Does anybody know
In : a = 10.0
In : b = 10.0 / 3.0
In : divmod(a, b)
In : math.floor(a / b) - 1.0
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list