PyWart: Language missing maximum constant of numeric types!

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Feb 27 04:51:43 CET 2012

```On Sun, 26 Feb 2012 18:32:27 -0800, alex23 wrote:

> On Feb 26, 6:29 am, Rick Johnson <rantingrickjohn... at gmail.com> wrote:
>> Sure there are float INFINITIES that work fine for ints and floats, but
>> where is the consistency?
>
> Sure, there are all of the COMPLEXITIES of floating point arithmetic but
> I want to ignore all of that and demand ridiculous consistencies. Why
> should I have to do float(some_int) < float('inf')

Ints and floats can be compared directly, no need to convert the int to a
float first:

>>> INF = float('inf')
>>> 23 < INF
True

Likewise Fractions and Decimals, at least in Python 3.2 (possibly not in
older versions):

>>> from fractions import Fraction
>>> from decimal import Decimal
>>> Fraction(33, 5) < INF
True
>>> Decimal("42.1568") < INF
True

> when it's a far
> better use of my time to spend days if not weeks bemoaning yet another
> language wart? Why should I be expected to know what float('inf')
> actually represents before making stupid demands like:
>
>> INFINITY need not be a int or a float or a str, or whatever.
>
> Please provide a non-contrived use case of an "infinite string".

Any lazy stream of characters that potentially goes on forever could be
considered an infinite string. But that's not what Rick is talking about.

He's talking about having a pair of special values, say, BIGGEST and
SMALLEST, which compare larger and smaller to any other value, regardless
of type and including strings, not literally a string with an infinite
number of characters.

I can see some value for this as a convenience, but not enough to make it
a built-in language feature. Every developer should have at least one
utility module with all the trivial code snippets they frequently use.
This belongs in there.

--
Steven

```