<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:8pt"><div><span style="font-size: 13px;">For whatever reason R chose NaN to be a subset of NA_real_, so I think it's better for Rcpp (which aims to provide C++ functionality in R) to follow the convention of R ...</span></div><div><span style="font-size: 13px;"><br></span></div><div><span style="font-size: 13px;">from the following tests in R we see that for most R function (especially those with na.rm argument), NaN and NA are actually treated in the same way:</span></div><div><span style="font-size: 13px;"><br></span></div><div><span><div><span style="font-size: 13px;">> x1 <- c(NaN, NA, 1.1, 2.2)</span><br></div><div><span style="font-size: 13px;">> x2 <- c(NA, NA, 1.1, 2.2)</span></div><div><span style="font-size: 13px;">> mean(x1)</span></div><div><span style="font-size: 13px;">[1]
NA</span></div><div><span style="font-size: 13px;">> mean(x2)</span></div><div><span style="font-size: 13px;">[1] NA</span></div><div><span style="font-size: 13px;">> mean(x1, na.rm=TRUE)</span></div><div><span style="font-size: 13px;">[1] 1.65</span></div><div><span style="font-size: 13px;">> mean(x2, na.rm=TRUE)</span></div><div><span style="font-size: 13px;">[1] 1.65</span></div><div><span><div><span style="font-size: 13px;">> is.na(x1)</span></div><div><span style="font-size: 13px;">[1] TRUE TRUE FALSE FALSE</span></div><div><span style="font-size: 13px;">> is.na(x2)</span></div><div><span style="font-size: 13px;">[1] TRUE TRUE FALSE FALSE</span></div><div style="font-size: 13px;"><br></div></span></div><div><span style="font-size: 13px;">of coz, there're some subtle differences (priority) in doing calculations on them:</span><br></div><div><span style="font-size: 13px;"><br></span></div><div><span
style="font-size: 13px;">> NaN + 1</span><br></div><div><span style="font-size: 13px;">[1] NaN</span></div><div><span style="font-size: 13px;">> NA + 1</span></div><div><span style="font-size: 13px;">[1] NA</span></div><div><span style="font-size: 13px;">> NA * Inf</span></div><div><span style="font-size: 13px;">[1] NA</span></div><div><span style="font-size: 13px;">> NaN * Inf</span></div><div><span style="font-size: 13px;">[1] NaN</span></div><div><span style="font-size: 13px;">> NaN * NA</span></div><div><span style="font-size: 13px;">[1] NA</span></div><div><br></div></span></div><span style="font-style: italic;"><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">Thomas,</span><br><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">On 2 October 2013 at 19:31, Thomas Tse wrote:</span><br><span style="font-size: 10px;">| is_na() does not handles R's NaN correctly, for the below
test.cpp:</span><br><span style="font-size: 10px;">[...]</span><br><span style="font-size: 10px;">| is it possible to apply this change in next release of Rcpp ?</span><br><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">Certainly. Though Romain has a point:</span><br><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">On 2 October 2013 at 13:36, Romain Francois wrote:</span><br><span style="font-size: 10px;">| The question is that do we want to be consistent with R or do we want</span><br><span style="font-size: 10px;">| something that makes sense.</span><br><span style="font-size: 10px;">|</span><br><span style="font-size: 10px;">| I believe that is_na should test if its argument is NA, and is_nan</span><br><span style="font-size: 10px;">| should check if is NaN</span><br><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">We have to make sure that we're doing is "consistent" for
various definitions</span><br><span style="font-size: 10px;">of consistent. IEEE754 only knows NaN and Inf; NA is an R extension.</span><br><span style="font-size: 12px;"><br></span><span style="font-size: 10px;">But from the top of my head I'd have to say I would want Rcpp to behave like</span><br><span style="font-size: 10px;">R over behaving like C++. But I could be swayed. Other views?</span><br><span style="color: rgb(136, 136, 136); font-size: 12px;"><br></span><span style="color: rgb(136, 136, 136); font-size: x-small;">Dirk</span><br><span style="color: rgb(136, 136, 136); font-size: x-small;"><br></span><span style="color: rgb(136, 136, 136); font-size: x-small;">--</span><br><span style="color: rgb(136, 136, 136); font-size: x-small;">Dirk Eddelbuettel | </span><a rel="nofollow" ymailto="mailto:edd@debian.org" target="_blank" href="mailto:edd@debian.org" style="font-size: x-small;">edd@debian.org</a><span style="color: rgb(136,
136, 136); font-size: x-small;"> | </span><a rel="nofollow" target="_blank" href="http://dirk.eddelbuettel.com/" style="font-size: x-small;">http://dirk.eddelbuettel.com</a><br><span style="font-size: x-small;"><br></span></span><div class="yui_3_7_2_38_1380718768649_60"><div class="yui_3_7_2_38_1380718768649_64"><div class="y_msg_container"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: x-small;"><br></span></div></div></div><div style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;"><div style="font-family: 'times new roman', 'new york', times, serif;"><div class="y_msg_container"><br></div> </div> </div> </div></body></html>