PEP238 and zope
Christian Tanzer
tanzer at swing.co.at
Wed Jul 25 11:43:20 EDT 2001
barry at zope.com (Barry A. Warsaw) wrote:
> >>>>> "CT" == Christian Tanzer <tanzer at swing.co.at> writes:
>
> CT> This isn't portable behavior. According to the python library
> CT> reference, `int` may round on some platforms.
>
> It also says:
>
> "This is ugly -- the language definition should require truncation
> towards zero."
Not in my book (2.1 of April 15, 2001). But that sentence is a good
addition.
> Okay so
>
> int(math.floor(a / b))
>
> or
>
> divmod(a, b)[0]
>
> are better. Either way, wrap it in a function called "div()" and use
> that where ever you absolutely must have integer division.
Unfortunately, I just learned that they were better even if `int`
behaved portably:
>>> divmod (5.,-2.)
(-3.0, -1.0)
>>> int(5.0/-2.0)
-2
>>> int(math.floor(5.0/-2.0))
-3
> really-portable-code-is-always-ugly-anyway-ly y'rs,
So-lets-make-it-even-uglier-?-ly y'rs,
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list