[Python-Dev] pyc files, constant folding and borderline portability issues (original) (raw)

Mark Dickinson dickinsm at gmail.com
Mon Apr 6 22:22:28 CEST 2009


On Mon, Apr 6, 2009 at 9:05 PM, Raymond Hettinger <python at rcn.com> wrote:

The code for the lsum() recipe is more readable with a line like:

 exp = long(mant * 2.0 ** 53) than with  exp = long(mant * 9007199254740992.0) It would be ashamed if code written like the former suddenly started doing the exponentation in the inner-loop or if the code got rewritten by hand as shown.

Well, I'd say that the obvious solution here is to compute the constant 2.053 just once, somewhere outside the inner loop. In any case, that value would probably be better written as 2.0DBL_MANT_DIG (or something similar).

As Antoine reported, the constant-folding caused quite a confusing bug report (issue #5593): the problem (when we eventually tracked it down) was that the folded constant was in a .pyc file, and so wasn't updated when the compiler flags changed.

Mark



More information about the Python-Dev mailing list