From Martin Maechler <maechler@stat.math.ethz.ch>  Tue Mar  3 14:28:24 1998
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Tue, 3 Mar 1998 15:28:24 +0100
Subject: ":" (seq) bug --> patch
In-Reply-To: <199803030936.KAA02061@sophie.ethz.ch> (message from Martin
 Maechler on Tue, 3 Mar 1998 10:36:49 +0100)
Message-ID: <199803031428.PAA02461@sophie.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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


":" (seq) bug --> patch
Martin Maechler