Beispiel #1
0
Variant ArrayUtil::Range(double low, double high, int64_t step /* = 1 */) {
  Array ret;
  if (low > high) { // Negative steps
    if (low - high < step || step <= 0) {
      throw_invalid_argument("step exceeds the specified range");
      return false;
    }
    rangeCheckAlloc((low - high) / step);
    for (; low >= high; low -= step) {
      ret.append((int64_t)low);
    }
  } else if (high > low) { // Positive steps
    if (high - low < step || step <= 0) {
      throw_invalid_argument("step exceeds the specified range");
      return false;
    }
    rangeCheckAlloc((high - low) / step);
    for (; low <= high; low += step) {
      ret.append((int64_t)low);
    }
  } else {
    ret.append((int64_t)low);
  }
  return ret;
}
Beispiel #2
0
Variant ArrayUtil::Range(double low, double high, double step /* = 1.0 */) {
  Array ret;
  double element;
  int64_t i;
  if (low > high) { // Negative steps
    if (low - high < step || step <= 0) {
      throw_invalid_argument("step exceeds the specified range");
      return false;
    }
    rangeCheckAlloc((low - high) / step);
    for (i = 0, element = low; element >= (high - DOUBLE_DRIFT_FIX);
         i++, element = low - (i * step)) {
      ret.append(element);
    }
  } else if (high > low) { // Positive steps
    if (high - low < step || step <= 0) {
      throw_invalid_argument("step exceeds the specified range");
      return false;
    }
    rangeCheckAlloc((high - low) / step);
    for (i = 0, element = low; element <= (high + DOUBLE_DRIFT_FIX);
         i++, element = low + (i * step)) {
      ret.append(element);
    }
  } else {
    ret.append(low);
  }
  return ret;
}