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

random832 at fastmail.us random832 at fastmail.us
Tue Mar 11 20:38:08 CET 2014


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.

>>> dis.dis(lambda x: 1.0/0.0)
  1           0 LOAD_CONST               1 (1.0)
              3 LOAD_CONST               2 (0.0)
              6 BINARY_TRUE_DIVIDE
              7 RETURN_VALUE

Maybe what needs to be done is to rigorously define what is a constant
expression (C does this) and explicitly state what context (including
rounding and traps) they take place in, independent of the runtime
context - which, then, an implementation that does _not_ do constant
folding must use to perform operations within a constant expression at
runtime.

Incidentally, did you know there's apparently no limit to how large an
integer ** will constant-fold? I say this because I assume if there were
it would be far below 2**9999999. On the other hand, 2.0**1024 doesn't
constant-fold.


More information about the Python-ideas mailing list