Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,14 +967,14 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con
case INTSXP: CHECK_RANGE(int, INTEGER, val<0 || val>255, val, _("%d (type '%s') at RHS position %d taken as 0 when assigning to type '%s' %s"))
case REALSXP: if (sourceIsI64)
CHECK_RANGE(int64_t, REAL, val<0 || val>255, val, _("%"PRId64" (type '%s') at RHS position %d taken as 0 when assigning to type '%s' %s"))
else CHECK_RANGE(double, REAL, !R_FINITE(val) || val<0.0 || val>256.0 || (int)val!=val, val, _("%f (type '%s') at RHS position %d either truncated (precision lost) or taken as 0 when assigning to type '%s' %s"))
else CHECK_RANGE(double, REAL, !isfinite(val) || val<0.0 || val>256.0 || (int)val!=val, val, _("%f (type '%s') at RHS position %d either truncated (precision lost) or taken as 0 when assigning to type '%s' %s"))
} break;
case INTSXP:
switch (TYPEOF(source)) {
case REALSXP: if (sourceIsI64)
CHECK_RANGE(int64_t, REAL, val!=NA_INTEGER64 && (val<=NA_INTEGER || val>INT_MAX), val, _("%"PRId64" (type '%s') at RHS position %d out-of-range (NA) when assigning to type '%s' %s"))
else CHECK_RANGE(double, REAL, !ISNAN(val) && (!within_int32_repres(val) || (int)val!=val), val, _("%f (type '%s') at RHS position %d out-of-range(NA) or truncated (precision lost) when assigning to type '%s' %s"))
case CPLXSXP: CHECK_RANGE(Rcomplex, COMPLEX, !((ISNAN(val.i) || (R_FINITE(val.i) && val.i==0.0)) &&
case CPLXSXP: CHECK_RANGE(Rcomplex, COMPLEX, !((ISNAN(val.i) || (isfinite(val.i) && val.i==0.0)) &&
(ISNAN(val.r) || (within_int32_repres(val.r) && (int)val.r==val.r))), val.r, _("%f (type '%s') at RHS position %d either imaginary part discarded or real part truncated (precision lost) when assigning to type '%s' %s"))
} break;
case REALSXP:
Expand All @@ -983,9 +983,9 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con
CHECK_RANGE(double, REAL, !ISNAN(val) && (!within_int64_repres(val) || (int64_t)val!=val), val, _("%f (type '%s') at RHS position %d out-of-range(NA) or truncated (precision lost) when assigning to type '%s' %s"))
break;
case CPLXSXP: if (targetIsI64)
CHECK_RANGE(Rcomplex, COMPLEX, !((ISNAN(val.i) || (R_FINITE(val.i) && val.i==0.0)) &&
(ISNAN(val.r) || (R_FINITE(val.r) && (int64_t)val.r==val.r))), val.r, _("%f (type '%s') at RHS position %d either imaginary part discarded or real part truncated (precision lost) when assigning to type '%s' %s"))
else CHECK_RANGE(Rcomplex, COMPLEX, !(ISNAN(val.i) || (R_FINITE(val.i) && val.i==0.0)), val.r, _("%f (type '%s') at RHS position %d imaginary part discarded when assigning to type '%s' %s"))
CHECK_RANGE(Rcomplex, COMPLEX, !((ISNAN(val.i) || (isfinite(val.i) && val.i==0.0)) &&
(ISNAN(val.r) || (isfinite(val.r) && (int64_t)val.r==val.r))), val.r, _("%f (type '%s') at RHS position %d either imaginary part discarded or real part truncated (precision lost) when assigning to type '%s' %s"))
else CHECK_RANGE(Rcomplex, COMPLEX, !(ISNAN(val.i) || (isfinite(val.i) && val.i==0.0)), val.r, _("%f (type '%s') at RHS position %d imaginary part discarded when assigning to type '%s' %s"))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/data.table.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdint.h> // for uint64_t rather than unsigned long long
#include <stdarg.h> // for va_list, va_start
#include <stdbool.h>
#include <math.h> // isfinite
#include "types.h"
#include "po.h"
#ifdef WIN32 // positional specifiers (%n$) used in translations; #4402
Expand Down
6 changes: 3 additions & 3 deletions src/fastmean.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SEXP fastmean(SEXP args)
break;
}
s /= n;
if(R_FINITE((double)s)) {
if(isfinite((double)s)) {
for (int i=0; i<l; ++i) {
if(ISNAN(REAL(x)[i])) continue;
t += (REAL(x)[i] - s);
Expand Down Expand Up @@ -98,7 +98,7 @@ SEXP fastmean(SEXP args)
s += REAL(x)[i];
}
s /= l;
if(R_FINITE((double)s)) {
if(isfinite((double)s)) {
for (int i=0; i<l; ++i) {
// no NA if got this far
t += (REAL(x)[i] - s);
Expand All @@ -123,7 +123,7 @@ SEXP fastmean(SEXP args)
si += COMPLEX(x)[i].i;
}
s /= n; si /= n;
if( R_FINITE((double)s) && R_FINITE((double)si) ) {
if( isfinite((double)s) && isfinite((double)si) ) {
for (int i=0; i<n; ++i) {
t += COMPLEX(x)[i].r - s;
ti += COMPLEX(x)[i].i - si;
Expand Down
10 changes: 5 additions & 5 deletions src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ static void range_d(double *x, int n, uint64_t *out_min, uint64_t *out_max, int
uint64_t min=0, max=0;
int na_count=0, infnan_count=0;
int i=0;
while(i<n && !R_FINITE(x[i])) { ISNA(x[i++]) ? na_count++ : infnan_count++; }
while(i<n && !isfinite(x[i])) { ISNA(x[i++]) ? na_count++ : infnan_count++; }
if (i<n) { max = min = dtwiddle(x[i++]); }
for(; i<n; i++) {
if (!R_FINITE(x[i])) { ISNA(x[i]) ? na_count++ : infnan_count++; continue; }
if (!isfinite(x[i])) { ISNA(x[i]) ? na_count++ : infnan_count++; continue; }
uint64_t tmp = dtwiddle(x[i]);
if (tmp>max) max=tmp;
else if (tmp<min) min=tmp;
Expand Down Expand Up @@ -426,7 +426,7 @@ uint64_t dtwiddle(double x) //const void *p, int i)
uint64_t u64;
} u; // local for thread safety
u.d = x; //((double *)p)[i];
if (R_FINITE(u.d)) {
if (isfinite(u.d)) {
if (u.d==0) u.d=0; // changes -0.0 to 0.0, issue #743
u.u64 ^= (u.u64 & 0x8000000000000000) ? 0xffffffffffffffff : 0x8000000000000000; // always flip sign bit and if negative (sign bit was set) flip other bits too
u.u64 += (u.u64 & dmask) << 1/*is this shift really correct. No need to shift*/ ; // when dround==1|2, if 8th|16th bit is set, round up before chopping last 1|2 bytes
Expand Down Expand Up @@ -750,15 +750,15 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
for (int i=0; i<nrow; i++) {
uint64_t elem=0;
if (!R_FINITE(xd[i])) {
if (!isfinite(xd[i])) {
if (isinf(xd[i])) elem = signbit(xd[i]) ? min-1 : max+1;
else {
if (nalast==-1) anso[i]=0; // for both NA and NaN
elem = ISNA(xd[i]) ? naval : nanval;
}
} else {
elem = dtwiddle(xd[i]); // TODO: could avoid twiddle() if all positive finite which could be known from range_d.
// also R_FINITE is repeated within dtwiddle() currently, wastefully given the if() above
// also isfinite is repeated within dtwiddle() currently, wastefully given the if() above
}
WRITE_KEY
}
Expand Down
2 changes: 1 addition & 1 deletion src/freadR.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ SEXP freadR(
args.nrowLimit = INT64_MAX;
if (!isReal(nrowLimitArg) || length(nrowLimitArg) != 1)
internal_error(__func__, "nrows not a single real. R level catches this."); // # nocov
if (R_FINITE(REAL(nrowLimitArg)[0]) && REAL(nrowLimitArg)[0] >= 0.0)
if (isfinite(REAL(nrowLimitArg)[0]) && REAL(nrowLimitArg)[0] >= 0.0)
args.nrowLimit = (int64_t)(REAL(nrowLimitArg)[0]);

args.logical01 = LOGICAL(logical01Arg)[0];
Expand Down
28 changes: 14 additions & 14 deletions src/froll.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ void frollmeanFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool
}
w += x[i]; // i==k-1
ans->dbl_v[i] = (double) (w / k); // first full sliding window, non-fill rollfun answer
if (R_FINITE((double) w)) { // proceed only if no NAs detected in first k obs, otherwise early stopping
if (isfinite((double) w)) { // proceed only if no NAs detected in first k obs, otherwise early stopping
for (uint64_t i=k; i<nx; i++) { // loop over obs, complete window, all remaining after partial window
w -= x[i-k]; // remove leaving row from sliding window
w += x[i]; // add current row to sliding window
ans->dbl_v[i] = (double) (w / k); // rollfun to answer vector
}
if (!R_FINITE((double) w)) { // mark to re-run with NA care
if (!isfinite((double) w)) { // mark to re-run with NA care
if (hasna==-1) { // raise warning
ans->status = 2;
snprintf(end(ans->message[2]), 500, _("%s: hasNA=FALSE used but NA (or other non-finite) value(s) are present in input, use default hasNA=NA to avoid this warning"), __func__);
Expand All @@ -96,14 +96,14 @@ void frollmeanFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool
int nc = 0; // NA counter within sliding window
int i; // iterator declared here because it is being used after for loop
for (i=0; i<k-1; i++) { // loop over leading observation, all partial window only; #loop_counter_not_local_scope_ok
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i]; // add only finite values to window aggregate
} else {
nc++; // increment NA count in current window
}
ans->dbl_v[i] = fill; // partial window fill all
}
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i]; // i==k-1
} else {
nc++;
Expand All @@ -116,12 +116,12 @@ void frollmeanFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool
ans->dbl_v[i] = narm ? (double) (w / (k - nc)) : NA_REAL; // some values in window are NA
}
for (uint64_t i=k; i<nx; i++) { // loop over obs, complete window, all remaining after partial window
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i]; // add only finite to window aggregate
} else {
nc++; // increment NA count in current window
}
if (R_FINITE(x[i-k])) {
if (isfinite(x[i-k])) {
w -= x[i-k]; // remove only finite from window aggregate
} else {
nc--; // decrement NA count in current window
Expand Down Expand Up @@ -158,7 +158,7 @@ void frollmeanExact(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool
for (int j=-k+1; j<=0; j++) { // sub-loop on window width
w += x[i+j]; // sum of window for particular observation
}
if (R_FINITE((double) w)) { // no need to calc roundoff correction if NAs detected as will re-call all below in truehasna==1
if (isfinite((double) w)) { // no need to calc roundoff correction if NAs detected as will re-call all below in truehasna==1
long double res = w / k; // keep results as long double for intermediate processing
long double err = 0.0; // roundoff corrector
for (int j=-k+1; j<=0; j++) { // nested loop on window width
Expand Down Expand Up @@ -268,13 +268,13 @@ void frollsumFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool n
}
w += x[i];
ans->dbl_v[i] = (double) w;
if (R_FINITE((double) w)) {
if (isfinite((double) w)) {
for (uint64_t i=k; i<nx; i++) {
w -= x[i-k];
w += x[i];
ans->dbl_v[i] = (double) w;
}
if (!R_FINITE((double) w)) {
if (!isfinite((double) w)) {
if (hasna==-1) {
ans->status = 2;
snprintf(end(ans->message[2]), 500, _("%s: hasNA=FALSE used but NA (or other non-finite) value(s) are present in input, use default hasNA=NA to avoid this warning"), __func__);
Expand All @@ -299,14 +299,14 @@ void frollsumFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool n
int nc = 0;
int i;
for (i=0; i<k-1; i++) { // #loop_counter_not_local_scope_ok
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i];
} else {
nc++;
}
ans->dbl_v[i] = fill;
}
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i];
} else {
nc++;
Expand All @@ -319,12 +319,12 @@ void frollsumFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool n
ans->dbl_v[i] = narm ? (double) w : NA_REAL;
}
for (uint64_t i=k; i<nx; i++) {
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i];
} else {
nc++;
}
if (R_FINITE(x[i-k])) {
if (isfinite(x[i-k])) {
w -= x[i-k];
} else {
nc--;
Expand Down Expand Up @@ -356,7 +356,7 @@ void frollsumExact(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool
for (int j=-k+1; j<=0; j++) {
w += x[i+j];
}
if (R_FINITE((double) w)) {
if (isfinite((double) w)) {
ans->dbl_v[i] = (double) w;
} else {
if (!narm) {
Expand Down
12 changes: 6 additions & 6 deletions src/frolladaptive.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void fadaptiverollmeanFast(double *x, uint64_t nx, ans_t *ans, int *k, double fi
w += x[i]; // cumulate in long double
cs[i] = (double) w;
}
if (R_FINITE((double) w)) { // no need to calc this if NAs detected as will re-calc all below in truehasna==1
if (isfinite((double) w)) { // no need to calc this if NAs detected as will re-calc all below in truehasna==1
#pragma omp parallel for num_threads(getDTthreads(nx, true))
for (uint64_t i=0; i<nx; i++) { // loop over observations to calculate final answer
if (i+1 == k[i]) {
Expand Down Expand Up @@ -74,7 +74,7 @@ void fadaptiverollmeanFast(double *x, uint64_t nx, ans_t *ans, int *k, double fi
return;
} // # nocov end
for (uint64_t i=0; i<nx; i++) { // loop over observations to calculate cumsum and cum NA counter
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i]; // add observation to running sum
} else {
nc++; // increment non-finite counter
Expand Down Expand Up @@ -126,7 +126,7 @@ void fadaptiverollmeanExact(double *x, uint64_t nx, ans_t *ans, int *k, double f
for (int j=-k[i]+1; j<=0; j++) { // sub-loop on window width
w += x[i+j]; // sum of window for particular observation
}
if (R_FINITE((double) w)) { // no need to calc roundoff correction if NAs detected as will re-call all below in truehasna==1
if (isfinite((double) w)) { // no need to calc roundoff correction if NAs detected as will re-call all below in truehasna==1
long double res = w / k[i]; // keep results as long double for intermediate processing
long double err = 0.0; // roundoff corrector
for (int j=-k[i]+1; j<=0; j++) { // sub-loop on window width
Expand Down Expand Up @@ -230,7 +230,7 @@ void fadaptiverollsumFast(double *x, uint64_t nx, ans_t *ans, int *k, double fil
w += x[i];
cs[i] = (double) w;
}
if (R_FINITE((double) w)) {
if (isfinite((double) w)) {
#pragma omp parallel for num_threads(getDTthreads(nx, true))
for (uint64_t i=0; i<nx; i++) {
if (i+1 == k[i]) {
Expand Down Expand Up @@ -263,7 +263,7 @@ void fadaptiverollsumFast(double *x, uint64_t nx, ans_t *ans, int *k, double fil
return;
} // # nocov end
for (uint64_t i=0; i<nx; i++) {
if (R_FINITE(x[i])) {
if (isfinite(x[i])) {
w += x[i];
} else {
nc++;
Expand Down Expand Up @@ -310,7 +310,7 @@ void fadaptiverollsumExact(double *x, uint64_t nx, ans_t *ans, int *k, double fi
for (int j=-k[i]+1; j<=0; j++) {
w += x[i+j];
}
if (R_FINITE((double) w)) {
if (isfinite((double) w)) {
ans->dbl_v[i] = (double) w;
} else {
if (!narm) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ bool within_int32_repres(double x) {
// N.B. (int)2147483647.99 is not undefined behaviour since s 6.3.1.4 of the C
// standard states that behaviour is undefined only if the integral part of a
// finite value of standard floating type cannot be represented.
return R_FINITE(x) && x < 2147483648 && x > -2147483648;
return isfinite(x) && x < 2147483648 && x > -2147483648;
}

bool within_int64_repres(double x) {
return R_FINITE(x) && x <= (double)INT64_MAX && x >= (double)INT64_MIN;
return isfinite(x) && x <= (double)INT64_MAX && x >= (double)INT64_MIN;
}

// used to error if not passed type double but this needed extra is.double() calls in calling R code
Expand Down
Loading