Exemplo n.º 1
0
int range(int argc, char *argv[], const int optind, const bool opt_short) {
  char *endptr;
  uint64_t start;
  uint64_t stop;
  uint64_t total;
  uint64_t count;

  if (optind + 2 < argc) {
    error("too many arguments\n");
    return 1;
  }

  start = strtoull(argv[optind], &endptr, 10);
  if (*endptr != '\0') {
    error("illegal argument: %s\n", argv[optind]);
    return 1;
  } else if (errno == ERANGE) {
    error("out of range: %s\n", argv[optind]);
    return 1;
  }

  if (optind + 1 == argc) {
    stop = start;
    start = 0;
  } else {
    stop = strtoull(argv[optind + 1], &endptr, 10);
    if (*endptr != '\0') {
      error("illegal argument: %s\n", argv[optind + 1]);
      return 1;
    } else if (errno == ERANGE) {
      error("out of range: %s\n", argv[optind + 1]);
      return 1;
    } else if (start > stop) {
      error("start must be <= stop\n");
      return 1;
    }
  }

  count = prime_range(start, stop, opt_short);
  if (count == UINT64_MAX) {
    error("unexpected error\n");
    return 1;
  }

  if (opt_short) {
    total = stop - start;
    printf("%" PRIu64 " of %" PRIu64 " (%f%%) in [%" PRIu64 ", %" PRIu64 ")\n",
           count, total, 100.0 * count / total, start, stop);
  }
  return 0;
}
Exemplo n.º 2
0
	prime_range prime(int first, int last)
	{
		BOOST_ASSERT( first <= last );
		BOOST_ASSERT( first >= 1 );
		return prime_range(first, last);
	}
Exemplo n.º 3
0
	prime_range prime(int first)
	{
		BOOST_ASSERT( first >= 1 );
		return prime_range(first);
	}