On Apr 6, 2009, at 10:38 AM, Stefan Behnel wrote: > Carl Witty wrote: >> On Mon, Apr 6, 2009 at 10:15 AM, Stefan Behnel wrote: >>> should we enable constant folding for floats by using the decimal >>> module? >> >> I don't think so. >> >> 1) Is there any advantage to doing constant folding in Cython instead >> of letting the C compiler do it? > > Well, yes. In many situations, Cython can use values that are known at > compile time to generate simpler code, e.g. avoid Python type > conversions > or move code sections into C completely. Loops are a great example. > Cython > 0.12 will bring another couple of enhancements here. > > Not sure if this really applies to float values, so we might end up > postponing this discussion until there is a concrete reason to > enable this. > > >> 2) If I write a constant floating-point expression, I expect it to be >> evaluated according to IEEE rounding rules. (So I would prefer doing >> the constant folding using Python floats, which will usually match >> the >> computations performed in the target, rather than the decimal module, >> which won't match the target.) > > Makes sense to me.
+1 Using the decimals module here seems strange. Note that one needs to use repr rather than str to get enough digits to accurately represent constants in the source. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
