Re: Use cases for quiet NaN comparison?
- From: Mensanator <mensanator@xxxxxxx>
- Date: Tue, 9 Dec 2008 16:12:41 -0800 (PST)
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.
.
- Follow-Ups:
- Re: Use cases for quiet NaN comparison?
- From: Adam Olsen
- Re: Use cases for quiet NaN comparison?
- References:
- Use cases for quiet NaN comparison?
- From: Adam Olsen
- Re: Use cases for quiet NaN comparison?
- From: Dik T. Winter
- Re: Use cases for quiet NaN comparison?
- From: David R Tribble
- Re: Use cases for quiet NaN comparison?
- From: Adam Olsen
- Use cases for quiet NaN comparison?
- Prev by Date: Re: How to win on Roulette 2
- Next by Date: Mapping function values to colors
- Previous by thread: Re: Use cases for quiet NaN comparison?
- Next by thread: Re: Use cases for quiet NaN comparison?
- Index(es):
Relevant Pages
|