[Python-ideas] Python Numbers as Human Concept Decimal System

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Mar 11 21:26:28 CET 2014


On 11 March 2014 19:46, Stefan Krah <stefan at bytereef.org> wrote:
> random832 at fastmail.us <random832 at fastmail.us> wrote:
>> On Tue, Mar 11, 2014, at 14:41, Stefan Krah wrote:
>> >   1) It must be possible to set rounding and traps, so the context
>> >      is not really fixed.
>>
>> It _must_ be possible? If there's a way to set rounding for floats, I
>> can't find it. As for traps, I can't find that either, but a constant
>> operation that may (will?) trap disables constant-folding.
>
> If we use IEEE, the default context would not raise anything -- infinities
> and NaNs would silently propagate.  This is valuable, but it should be
> possible switch it off.  Settting rounding is obviously valuable, too.

I was intending that it would be possible to use the traps and flags
on this context. Perhaps Stefan knows something I don't but I thought
that the constant folder could just use a hyper-sensitive context and
check for exceptions (or otherwise check the flags). I assumed this is
how it handled cases like '1 / 0' and '1.0 * 10 ** 1000' which are not
folded so that they can raise exceptions at the appropriate time.

Rounding is a trickier one. It would be possible to do the same thing
by having the constant folder trap Inexact but it's a little more
limiting since it applies to expressions that are more likely to have
useful values.


Oscar


More information about the Python-ideas mailing list