The R Project SVN R

Rev

Rev 50879 | Rev 51181 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 50879 Rev 51095
Line 448... Line 448...
448
/*
448
/*
449
   'along' has to be used on an unevaluated argument, and evalList
449
   'along' has to be used on an unevaluated argument, and evalList
450
   tries to evaluate language objects.
450
   tries to evaluate language objects.
451
 */
451
 */
452
 
452
 
453
#define FEPS 1e-7
453
#define FEPS 1e-10
454
/* to match seq.default */
454
/* to match seq.default */
455
SEXP attribute_hidden do_seq(SEXP call, SEXP op, SEXP args, SEXP rho)
455
SEXP attribute_hidden do_seq(SEXP call, SEXP op, SEXP args, SEXP rho)
456
{
456
{
457
    SEXP ans = R_NilValue /* -Wall */, ap, tmp, from, to, by, len, along;
457
    SEXP ans = R_NilValue /* -Wall */, ap, tmp, from, to, by, len, along;
458
    int i, nargs = length(args), lf, lout = NA_INTEGER;
458
    int i, nargs = length(args), lf, lout = NA_INTEGER;
Line 546... Line 546...
546
	    }
546
	    }
547
	    if(n > (double) INT_MAX)
547
	    if(n > (double) INT_MAX)
548
		errorcall(call, _("'by' argument is much too small"));
548
		errorcall(call, _("'by' argument is much too small"));
549
	    if(n < - FEPS)
549
	    if(n < - FEPS)
550
		errorcall(call, _("wrong sign in 'by' argument"));
550
		errorcall(call, _("wrong sign in 'by' argument"));
551
	    nn = (int)(n + FEPS);
-
 
552
	    if(TYPEOF(from) == INTSXP && 
551
	    if(TYPEOF(from) == INTSXP && 
553
	       TYPEOF(to) == INTSXP && 
552
	       TYPEOF(to) == INTSXP && 
554
	       TYPEOF(by) == INTSXP) {
553
	       TYPEOF(by) == INTSXP) {
555
		int *ia, ifrom = asInteger(from), iby = asInteger(by);
554
		int *ia, ifrom = asInteger(from), iby = asInteger(by);
-
 
555
		/* With the current limits on integers and FEPS
-
 
556
		   reduced below 1/INT_MAX this is the same as the
-
 
557
		   next, so this is future-proofing against longer integers.
-
 
558
		*/
-
 
559
		nn = (int)n;
556
		/* seq.default gives integer result from from + (0:n)*by */
560
		/* seq.default gives integer result from 
-
 
561
		   from + (0:n)*by 
-
 
562
		*/
557
		ans = allocVector(INTSXP, nn+1);
563
		ans = allocVector(INTSXP, nn+1);
558
		ia = INTEGER(ans);
564
		ia = INTEGER(ans);
559
		for(i = 0; i <= nn; i++)
565
		for(i = 0; i <= nn; i++)
560
		    ia[i] = ifrom + i * iby;
566
		    ia[i] = ifrom + i * iby;
561
	    } else {
567
	    } else {
-
 
568
		nn = (int)(n + FEPS);
562
		ans = allocVector(REALSXP, nn+1);
569
		ans = allocVector(REALSXP, nn+1);
563
		ra = REAL(ans);
570
		ra = REAL(ans);
564
		for(i = 0; i <= nn; i++)
571
		for(i = 0; i <= nn; i++)
565
		    ra[i] = rfrom + i * rby;
572
		    ra[i] = rfrom + i * rby;
566
		/* Added in 2.9.0 */
573
		/* Added in 2.9.0 */