[Python-Dev] infinities

Adam Olsen rhamph at gmail.com
Mon Nov 27 10:17:10 CET 2006


On 11/26/06, tomer filiba <tomerfiliba at gmail.com> wrote:
> i found several places in my code where i use positive infinity
> (posinf) for various things, i.e.,
>
>
> i like the concept, but i hate the "1e10000" stuff... why not add
> posint, neginf, and nan to the float type? i find it much more readable as:
>
>     if limit < 0:
>         limit = float.posinf
>
> posinf, neginf and nan are singletons, so there's no problem with
> adding as members to the type.

There's no reason this has to be part of the float type.  Just define
your own PosInf/NegInf singletons and PosInfType/NegInfType classes,
giving them the appropriate special methods.

NaN is a bit iffier, but in your case it's sufficient to raise an
exception whenever it would be created.

Consider submitting it to the Python Cookbook when you're done. ;)

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-Dev mailing list