[Python-ideas] Suggestion: Extend integers to include iNaN
oscar.j.benjamin at gmail.com
Sun Sep 30 18:52:40 EDT 2018
On Sun, 30 Sep 2018 at 02:01, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, Sep 29, 2018 at 09:43:42PM +0100, Oscar Benjamin wrote:
> > On Sat, 29 Sep 2018 at 19:38, Steve Barnes <gadgetsteve at live.co.uk> wrote:
> > > > I converted to int because I needed a whole number, this was intended to
> > > represent some more complex process where a value is converted to a
> > > whole number down in the depths of the processing.
> > Your requirement to have a whole number cannot meaningfully be
> > satisfied if your input is nan so an exception is the most useful
> > result.
> Not to Steve it isn't.
> Be careful about making value judgements like that: Steve is asking for
> an integer NAN because for *him* an integer NAN is more useful than an
> exception. You shouldn't tell him that he is wrong, unless you know his
> use-case and his code, which you don't.
Then he can catch the exception and do something else. If I called
int(x) because my subsequent code "needed a whole number" then I would
definitely not want to end up with a nan. The proposal requested is
that int(x) could return something other than a well defined integer.
That would break a lot of code!
In what way is iNaN superior to a plain nan? In C this sort of thing
makes sense but in Python there's no reason you can't just use
float('nan'). (This was raised by Serhiy earlier in the thread,
resulting in Steve saying that he wants int(float('nan')) to return
iNaN which then results in the quoted context above).
I don't mean to make a judgment about Steve's use-cases: I have read
the messages in this thread and I haven't yet seen a use-case for this
More information about the Python-ideas