convert_to_int64_if_sum_breaks_numeric_ <- function(DT, cols, thresh=.Machine$double.xmax/10, showWarnings=TRUE, verbose=TRUE) {
  if (!length(cols))
    return(DT)

  if (!is.data.table(DT))
    stop ("DT must be a data.table -- it is a '", class(DT)[[1]], "'")
  
  for (col in cols) {
    if (col %ni% names(DT)) {
      verboseMsg(showWarnings, "col '", col, "' is not a name of DT -- cannot check for conversion to int64")
    } else if (sumn(as.num.nowarn(DT[[col]])) > thresh) {
      verboseMsg(verbose, "Converting col '", col, "' to int 64")
      DT[, (col) := bit64::as.integer64(as.numeric(get(col)))]
    } else if (!is.numeric(DT[[col]]) || is.integer(DT[[col]])) {
      DT[, (col) := as.numeric(get(col))]      
    }
  }
}
