Martin Maechler
1998-Mar-03 09:36 UTC
":" (seq) bug -- should not always coerce to integer!
The problem seems that ":" always coerces to integer, but should not.. 9.9:12 ## R: [1] 9 10 11 ## S-plus 3.4: [1] 9.9 10.9 11.9 ## and many more examples.... -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I corrected the bug myself. Here is a patch --- seq.c.~1~ Fri Jan 16 16:07:00 1998 +++ seq.c Tue Mar 3 15:25:27 1998 @@ -1,6 +1,6 @@ /* - * R : A Computer Langage for Statistical Data Analysis - * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka + * R : A Computer Language for Statistical Data Analysis + * Copyright (C) 1995-1998 Robert Gentleman and Ross Ihaka * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +17,18 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* The `` x:y '' primitive calls do_seq(.); + * + * do_seq(.) calls cross(.) if both arguments are factors + * and seq(.) otherwise. + */ + #include "Defn.h" #include "Mathlib.h" static SEXP seq(SEXP call, SEXP s1, SEXP s2) { - int i, n; + int i, n, in1; double n1, n2; SEXP ans; @@ -37,28 +43,31 @@ if (ISNAN(n1) || ISNAN(n2)) errorcall(call, "NA/NaN argument\n"); - if (n1 <= INT_MIN || n2 <= INT_MIN || n1 > INT_MAX || n2 > INT_MAX) + if (n1 <= INT_MIN || n2 <= INT_MIN || n1 > INT_MAX || n2 > INT_MAX + || abs(n2 - n1) >= INT_MAX) errorcall(call, "argument too large in magnitude\n"); - if (n1 <= n2) { - n = n2 - n1 + 1 + FLT_EPSILON; - ans = allocVector(INTSXP, n); - for (i = 0; i < n; i++) - INTEGER(ans)[i] = n1 + i; - } - else { - n = n1 - n2 + 1 + FLT_EPSILON; + n = abs(n2 - n1) + 1 + FLT_EPSILON; + if (n1 == (in1 = (int)(n1))) { ans = allocVector(INTSXP, n); - for (i = 0; i < n; i++) - INTEGER(ans)[i] = n1 - i; + if (n1 <= n2) + for (i = 0; i < n; i++) INTEGER(ans)[i] = in1 + i; + else + for (i = 0; i < n; i++) INTEGER(ans)[i] = in1 - i; + } else { + ans = allocVector(REALSXP, n); + if (n1 <= n2) + for (i = 0; i < n; i++) REAL(ans)[i] = n1 + i; + else + for (i = 0; i < n; i++) REAL(ans)[i] = n1 - i; } return ans; } /* cross - the "cross" of two factors */ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Maybe Matching Threads
- R-beta: R-0.62.1 under Digital Unix
- Altrep and translations (was " Description of error is untranslated when ....")
- Altrep and translations (was " Description of error is untranslated when ....")
- [LLVMdev] Related constant folding of floating point values
- Increasing Max Vector Length