rocket at google.com
2009-Jul-14 04:15 UTC
[Rd] Incorrect comment about ISNA(x) in Arith.h (PR#13826)
R-2.9.0/include/R_ext/Arith.h has: int R_IsNA(double); /* True for R's NA only */ int R_IsNaN(double); /* True for special NaN, *not* for NA */ int R_finite(double); /* True if none of NA, NaN, +/-Inf */ #define ISNA(x) R_IsNA(x) /* True for *both* NA and NaN. The first and last lines are contradictory - if R_IsNA is true only for NA, not NaN, then ISNA should be the same. Venables & Ripley S Programming p 137 indicates that "ISNA does not detect NaN s" Here's a little .c file and R transcript that shows that V&R are correct, ISNA(x) is not True for NaN So the last comment should read /* True for NA, not NaN #include "R.h" void mysum(double *x) { double sum = 0.0; sum = x[0] + x[1] + x[2]; if (ISNA(sum)) PROBLEM "sum is NA" WARNING(NULL_ENTRY); if (ISNAN(sum)) PROBLEM "sum is NAN" WARNING(NULL_ENTRY); if (!(R_FINITE(sum))) PROBLEM "sum is not finite" WARNING(NULL_ENTRY); return; }> dyn.load("~/R/work/bug.so") > .C("mysum", c(NaN, 0.0, 0.0), NAOK = TRUE, DUP = FALSE)[[1]] [1] NaN 0 0 Warning messages: 1: sum is NAN 2: sum is not finite --please do not edit the information below-- Version: platform = x86_64-unknown-linux-gnu arch = x86_64 os = linux-gnu system = x86_64, linux-gnu status = major = 2 minor = 9.0 year = 2009 month = 04 day = 17 svn rev = 48333 language = R version.string = R version 2.9.0 (2009-04-17) Locale: LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C Search Path: .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate, package:splus2Rgoogle, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base
maechler at stat.math.ethz.ch
2009-Jul-16 16:25 UTC
[Rd] Incorrect comment about ISNA(x) in Arith.h (PR#13826)
>>>>> Tim Hesterberg <rocket at google.com> >>>>> on Tue, 14 Jul 2009 06:15:17 +0200 (CEST) writes:> R-2.9.0/include/R_ext/Arith.h has: > int R_IsNA(double); /* True for R's NA only */ > int R_IsNaN(double); /* True for special NaN, *not* for NA */ > int R_finite(double); /* True if none of NA, NaN, +/-Inf */ > #define ISNA(x) R_IsNA(x) > /* True for *both* NA and NaN. Hi Tim, thanks for that, but you have cited things out of context. The last line in the above is the beginning of a longer comment which introduces '#define ISNAN(x)' and is all about ISNAN(.) and hence is correct. So really, there's no bug, not even in comments of the sources {{which are *not* part of the API, so very pedantically cannot have a bug... but of course, we'd still be glad for reports like yours particularly if they are about an error ..}} In order to ensure that such a confusion is less likely to happen again, I've very slightly changed that part now [svn rev 48943]. Regards, Martin Maechler, ETH Zurich > The first and last lines are contradictory - if R_IsNA is true only > for NA, not NaN, then ISNA should be the same. > Venables & Ripley S Programming p 137 indicates that > "ISNA does not detect NaN s" > Here's a little .c file and R transcript that shows that V&R are correct, > ISNA(x) is not True for NaN > So the last comment should read > /* True for NA, not NaN > #include "R.h" > void mysum(double *x) > { > double sum = 0.0; > sum = x[0] + x[1] + x[2]; > if (ISNA(sum)) > PROBLEM "sum is NA" WARNING(NULL_ENTRY); > if (ISNAN(sum)) > PROBLEM "sum is NAN" WARNING(NULL_ENTRY); > if (!(R_FINITE(sum))) > PROBLEM "sum is not finite" WARNING(NULL_ENTRY); > return; > } >> dyn.load("~/R/work/bug.so") >> .C("mysum", c(NaN, 0.0, 0.0), NAOK = TRUE, DUP = FALSE) > [[1]] > [1] NaN 0 0 > Warning messages: > 1: sum is NAN > 2: sum is not finite > --please do not edit the information below-- > Version: > platform = x86_64-unknown-linux-gnu > arch = x86_64 > os = linux-gnu > system = x86_64, linux-gnu > status = > major = 2 > minor = 9.0 > year = 2009 > month = 04 > day = 17 > svn rev = 48333 > language = R > version.string = R version 2.9.0 (2009-04-17) > Locale: > LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C > Search Path: > .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate, package:splus2Rgoogle, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel