
i found several places in my code where i use positive infinity (posinf) for various things, i.e.,
def readline(self, limit = -1): if limit < 0: limit = 1e10000 # posinf chars = [] while limit > 0: ch = self.read(1) chars.append(ch) if not ch or ch == "\n": break limit -= 1 return "".join(chars)
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.
-tomer

On 11/26/06, tomer filiba tomerfiliba@gmail.com wrote:
i found several places in my code where i use positive infinity (posinf) for various things, i.e.,
def readline(self, limit = -1): if limit < 0: limit = 1e10000 # posinf chars = [] while limit > 0: ch = self.read(1) chars.append(ch) if not ch or ch == "\n": break limit -= 1 return "".join(chars)
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.
sys.maxint makes more sense there. Or you could change it to "while limit != 0" and set it to -1 (though I probably wouldn't actually do that)...
There is already a PEP 754 for float constants, which is implemented in the fpconst module (see CheeseShop). It's not (yet) part of the stdlib though.
-bob

sys.maxint makes more sense there.
no, it requires *infinity* to accomplish x - y == x; y != 0, for example:
while limit > 0: limit -= len(chunk)
with limit = posinf, the above code should be equivalent to "while True".
There is already a PEP 754 for float constants
okay, that would suffice. but why isn't it part of stdlib already? the pep is three years old... it should either be rejected or accepted. meanwhile, there are lots of missing API functions in the floating-point implementation...
besides, all the suggested APIs should be part of the float type, not a separate module. here's what i want:
f = 5.0 f.is_infinity()
False
float.PosInf
1.#INF
-tomer
On 11/26/06, Bob Ippolito bob@redivi.com wrote:
On 11/26/06, tomer filiba tomerfiliba@gmail.com wrote:
i found several places in my code where i use positive infinity (posinf) for various things, i.e.,
def readline(self, limit = -1): if limit < 0: limit = 1e10000 # posinf chars = [] while limit > 0: ch = self.read(1) chars.append(ch) if not ch or ch == "\n": break limit -= 1 return "".join(chars)
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.
sys.maxint makes more sense there. Or you could change it to "while limit != 0" and set it to -1 (though I probably wouldn't actually do that)...
There is already a PEP 754 for float constants, which is implemented in the fpconst module (see CheeseShop). It's not (yet) part of the stdlib though.
-bob

tomer filiba wrote:
no, it requires *infinity* to accomplish x - y == x; y != 0, for example:
while limit > 0: limit -= len(chunk)
with limit = posinf, the above code should be equivalent to "while True".
that's a remarkably stupid way to count bytes. if you want to argue for additions to the language, you could at least bother to come up with a sane use case.
</F>

tomer filiba schrieb:
okay, that would suffice. but why isn't it part of stdlib already? the pep is three years old... it should either be rejected or accepted. meanwhile, there are lots of missing API functions in the floating-point implementation...
It's not rejected because people keep requesting the feature, and not accepted because it's not implementable in general (i.e. it is difficult to implement on platforms where the double type is not IEEE-754).
Regards, Martin

On 11/26/06, tomer filiba tomerfiliba@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. ;)
participants (5)
-
"Martin v. Löwis"
-
Adam Olsen
-
Bob Ippolito
-
Fredrik Lundh
-
tomer filiba