[Rd] Inconsistency in treating NaN-results?

Mark van der Loo mark.vanderloo at gmail.com
Thu Nov 26 10:07:17 CET 2015


This question is more out of curiosity than a complaint or suggestion, but
I'm just wondering.

The behavior of R on calculations that result in NaN seems a bit
inconsistent.

# this is expected:
> 0/0
[1] NaN

# but this gives a warning
> sin(Inf)
[1] NaN
Warning message:
In sin(Inf) : NaNs produced

# and this again does not
> exp(NaN)
[1] NaN


Conceptually, I like to think that R computes over the real line augmented
with NaN, Inf, -Inf, NaN, and NA (which is technically also NaN). As far as
I know, this set is closed under R's arithmetic operations and mathematical
functions (following the IEEE standard on double precision). If that's the
case, the result sin(Inf)=NaN seems normal to me and a warning is
unnecessary.

So why the choice to have warning on sin(Inf), but not on 0/0 or exp(Nan)?
Is it just historical or am I missing a reasoning or some standard?


Best,
Mark

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=nl_NL.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C

	[[alternative HTML version deleted]]



More information about the R-devel mailing list