Re: Use cases for quiet NaN comparison?



On Dec 9, 11:53 am, Adam Olsen <rha...@xxxxxxxxx> wrote:
On Dec 9, 8:16 am, David R Tribble <da...@xxxxxxxxxxx> wrote:





Adam Olsen writes:
I'm aware of the behaviour IEEE 754 requires (as best I can be,
without having my own copy of it.)  However, I'm not aware of any
rationale for the behaviour.  It seems to be a Parable of the Monkeys.

Can anybody enlighten me?

Dik T. Winter wrote:
Why do you think it makes sense to compare something that is not a number
with a number?  Anyway, the appearance of a NaN in a calculation shows
that something has gone fundamentally wrong in a calculation, and the NaN
is an out of band signal to indicate this.

Exactly. Once you get a NaN, a non-number, then you no longer
have a valid numeric value. So arithmetic and comparison operations
make no sense, and all you can get from further operations is
non-numeric values. It's not a number, so it doesn't compare to any
valid number, nor to any other non-number.

Or perhaps you are asking why NaN operations are silent instead
of triggering exceptions?

In general, having no sane result should produce an exception.  In
this case there's a clear desire for it to continue quietly, ie a
quiet NaN is pretending it *is* a number.  There must be some further
logic in how it behaves.

In databases, we have Null, which represents an empty field.

All comparisons to Nulls return False:
A > Null = False
A = Null = False
A < Null = False

All expresions involving a Null evaluate to Null:
A + Null = Null
A * Null = Null

Now, in a surface countour application, this Null result
does NOT evaluate to 0 like the stupid Excel spreadsheet
does (which would make your water table appear to dip down
to sea level at one point, which is meaningless). Instead,
the Kriging algorithm ignores the empty datapoint and
simply uses larger triangles to interpolate around the hole
in the data. Yes, the resulting contours are less accurate
than if you had a datapoint, but it's better than falsely
evaluating nothing as 0, which Excel does. And this is
preferable to raising an exception since the Kriging algorithm
knows how to handle it.


Btw, thank you both for replying.  This has been niggling at my brain
for years.


.



Relevant Pages

  • Re: Use cases for quiet NaN comparison?
    ... that something has gone fundamentally wrong in a calculation, and the NaN ... So arithmetic and comparison operations ... preferable to raising an exception since the Kriging algorithm ...
    (sci.math)
  • Re: float("nan") in set or as key
    ... Isn't a signaling nan basically the same as an exception? ... did indeed support IEEE floating point, which specifies signalling nan)? ... The actual hardware implementations handle ...
    (comp.lang.python)
  • Re: float("nan") in set or as key
    ... specifically talking about NAN == NAN raising an exception rather than ... calculation throws an exception, the calculation as a whole throws an ... NAN is a sentinel for an invalid operation. ...
    (comp.lang.python)
  • Re: Division durch Null
    ... IMO gibt es nicht nur INF, sondern sogar +/- INF und NAN. ... |x87 control word) and the operation causes a zero-divide exception (sets ... |the ZE bit in the x87 status word to 1), ...
    (de.comp.lang.c)
  • Re: When is min(a, b) != min(b, a)?
    ... in a non numeric result would throw an exception. ... NaN results, would get silent NaN where no exceptions would be thrown. ... I also think this would be the ideal situation. ... require a lot of thought, planning, a PEP or two, and some hard work ...
    (comp.lang.python)