Skip to content

Commit c340d1d

Browse files
Further simplify -- first* helpers not needed if we just return bool
1 parent 2eb6519 commit c340d1d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/utils.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,36 @@ bool within_int64_repres(double x) {
1111
return R_FINITE(x) && x <= (double)INT64_MAX && x >= (double)INT64_MIN;
1212
}
1313

14-
static R_xlen_t firstNonInt32(SEXP x) {
14+
// used to error if not passed type double but this needed extra is.double() calls in calling R code
15+
// which needed a repeat of the argument. Hence simpler and more robust to return false when not type double.
16+
bool isRealReallyInt32(SEXP x) {
17+
if (!isReal(x))
18+
return false;
1519
R_xlen_t n=xlength(x), i=0;
1620
const double *dx = REAL(x);
1721
while (i<n &&
1822
( ISNA(dx[i]) ||
1923
(within_int32_repres(dx[i]) && dx[i]==(int)(dx[i])))) {
2024
i++;
2125
}
22-
return i==n ? 0 : i+1;
26+
return i!=n;
2327
}
2428

25-
static R_xlen_t firstNonInt64(SEXP x) {
29+
SEXP isRealReallyInt32R(SEXP x) {
30+
return ScalarLogical(isRealReallyInt32(x));
31+
}
32+
33+
bool isRealReallyInt64(SEXP x) {
34+
if (!isReal(x))
35+
return false;
2636
R_xlen_t n=xlength(x), i=0;
2737
const double *dx = REAL(x);
2838
while (i<n &&
2939
( ISNA(dx[i]) ||
3040
(within_int64_repres(dx[i]) && dx[i]==(int64_t)(dx[i])))) {
3141
i++;
3242
}
33-
return i==n ? 0 : i+1;
34-
}
35-
36-
// used to error if not passed type double but this needed extra is.double() calls in calling R code
37-
// which needed a repeat of the argument. Hence simpler and more robust to return false when not type double.
38-
bool isRealReallyInt32(SEXP x) {
39-
return isReal(x) ? firstNonInt32(x)==0 : false;
40-
}
41-
42-
SEXP isRealReallyInt32R(SEXP x) {
43-
return ScalarLogical(isRealReallyInt32(x));
44-
}
45-
46-
bool isRealReallyInt64(SEXP x) {
47-
return isReal(x) ? firstNonInt64(x)==0 : false;
43+
return i!=n;
4844
}
4945

5046
SEXP isRealReallyInt64R(SEXP x) {

0 commit comments

Comments
 (0)