Skip to content

Inconsistency in treating NaN-results?

1 message · Mark van der Loo

#
Thank you very much, Greg and Bill for clearing things up.

As said, it was more out of curiosity then anything else.

I think my examples were not completely inconsistent (as Greg mentioned)
since arithmetic operations that generate NaN's do so without warning:
[1] NaN
[1] NaN,

while mathematical functions generating NaN's do (as noted by Greg):
[1] NaN
Warning message:
In sin(Inf) : NaNs produced
[1] NaN
[1] NaN
Warning message:
In gamma(-1) : NaNs produced

And this was what surprised me. The rule thus seems to be: arithmetic
operations do it without warning, standard math functions do it with a
warning. I think that is totally fine. As long as we can reason about what
to expect, we're good.

To answer Bill's question
I think I like the behavior as it is (not producing NaN), but that's
because I feel I have a reasonable working knowledge about numerical
precision issues. I'm not an expert, but I believe that at least my
internal alarm bells start ringing at the right time, and my old copy of
Stoer and Bulirsch[1] is never much more then an arm's length away. So it
all depends on what user you're aiming at when implementing such things. A
(switchable) warning about loss of precision without returning NaN would
probably be a reasonable compromise.

Best,
Mark

[1] https://books.google.nl/books?id=1oDXWLb9qEkC



Op di 1 dec. 2015 om 00:09 schreef William Dunlap <wdunlap at tibco.com>: