|
1 | 1 | /* |
2 | 2 | * R : A Computer Language for Statistical Data Analysis |
3 | | - * Copyright (C) 1998-2023 The R Core Team. |
| 3 | + * Copyright (C) 1998-2025 The R Core Team. |
4 | 4 | * Copyright (C) 1995-1998 Robert Gentleman and Ross Ihaka |
5 | 5 | * |
6 | 6 | * This program is free software; you can redistribute it and/or modify |
@@ -109,7 +109,7 @@ static SEXP seq_colon(double n1, double n2, SEXP call) |
109 | 109 |
|
110 | 110 | Rboolean useInt = (n1 <= INT_MAX) && (n1 == (int) n1); |
111 | 111 | if(useInt) { |
112 | | - if(n1 <= INT_MIN || n1 > INT_MAX) |
| 112 | + if(n1 <= INT_MIN) /* know n1 <= INT_MAX */ |
113 | 113 | useInt = FALSE; |
114 | 114 | else { |
115 | 115 | /* r := " the effective 'to' " of from:to */ |
@@ -787,11 +787,12 @@ attribute_hidden SEXP do_rep(SEXP call, SEXP op, SEXP args, SEXP rho) |
787 | 787 |
|
788 | 788 |
|
789 | 789 | /* |
790 | | - This is a primitive SPECIALSXP with internal argument matching, |
791 | | - implementing seq.int(). |
| 790 | + This is a primitive SPECIALSXP with internal argument matching, implementing |
792 | 791 |
|
793 | | - 'along' has to be used on an unevaluated argument, and evalList |
794 | | - tries to evaluate language objects. |
| 792 | + seq.int(from, to, by, length.out, along.with, ...) |
| 793 | +
|
| 794 | + 'along' has to be used on an unevaluated argument, and evalList |
| 795 | + tries to evaluate language objects. |
795 | 796 | */ |
796 | 797 | #define FEPS 1e-10 |
797 | 798 | /* to match seq.default */ |
@@ -832,7 +833,7 @@ attribute_hidden SEXP do_seq(SEXP call, SEXP op, SEXP args, SEXP rho) |
832 | 833 | errorcall(call, _("'%s' must be a finite number"), "from"); |
833 | 834 | ans = seq_colon(1.0, rfrom, call); |
834 | 835 | } |
835 | | - else if (lf) |
| 836 | + else if (lf) // typically seq(<vec>) , length(<vec>) >= 2 |
836 | 837 | ans = seq_colon(1.0, (double)lf, call); |
837 | 838 | else |
838 | 839 | ans = allocVector(INTSXP, 0); |
@@ -884,13 +885,16 @@ attribute_hidden SEXP do_seq(SEXP call, SEXP op, SEXP args, SEXP rho) |
884 | 885 | ans = to; // is *not* missing in this case |
885 | 886 | goto done; |
886 | 887 | } |
887 | | - double n, rby = asReal(by); |
888 | | - Rboolean finite_del = R_FINITE(del); |
889 | | - if(finite_del) { |
890 | | - n = del/rby; |
891 | | - } else { // overflow in (to - from) when both are finite |
892 | | - n = rto/rby - rfrom/rby; |
| 888 | + double rby = asReal(by); |
| 889 | + if((rby == 1. && del > 0.) || |
| 890 | + (rby == -1. && del < 0.)) { // --> treat as if missing (return integer) |
| 891 | + ans = seq_colon(rfrom, rto, call); |
| 892 | + goto done; |
893 | 893 | } |
| 894 | + Rboolean finite_del = R_FINITE(del); |
| 895 | + double n = (finite_del) |
| 896 | + ? del/rby |
| 897 | + : rto/rby - rfrom/rby; /* overflow in (to - from) when both are finite */ |
894 | 898 | if(!R_FINITE(n)) { |
895 | 899 | if(del == 0.0 && rby == 0.0) { |
896 | 900 | ans = miss_from ? ScalarReal(rfrom) : from; |
@@ -1047,7 +1051,7 @@ attribute_hidden SEXP do_seq(SEXP call, SEXP op, SEXP args, SEXP rho) |
1047 | 1051 | done: |
1048 | 1052 | UNPROTECT(1); |
1049 | 1053 | return ans; |
1050 | | -} |
| 1054 | +} // do_seq() |
1051 | 1055 |
|
1052 | 1056 | attribute_hidden SEXP do_seq_along(SEXP call, SEXP op, SEXP args, SEXP rho) |
1053 | 1057 | { |
|
0 commit comments