Ejemplo n.º 1
0
int main(int argc, char** argv) {
  int num = 100000;
  if (argc >= 2)
    num = atoi(argv[1]);
 
  Timer2 timer;

  timer.start();
  double d = 0;
  for (int i=1; i<=num; ++i) {
    d += term<double>(i);
  }
  timer.stop();
  std::cout << "d=" << std::setprecision(17) << d << std::endl;
  std::cout << "IEEE double tooks " << timer.get_mseconds() << " mseconds." << std::endl;

  Expr e = sum(term<Expr>, 1, num);
  timer.start();
  BigFloat r = e.approx(60, CORE_INFTY);
  timer.stop();

  std::cout << "r=" << r << std::endl;
  std::cout << "it tooks " << timer.get_mseconds() << " mseconds." << std::endl;

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
  int num = 100000;
  if (argc >= 2)
    num = atoi(argv[1]);

  if(num < 2)
	cerr << "ERROR!!! Input argument should be greater than 1." << endl;

  cout << setprecision(60);
	
  Timer2 timer;
  BigFloat r;

  timer.start();

#ifdef _USE_PROD
  Expr e = product(term, 1, num);
#else
  Expr e = prod(term, 1, num);
#endif

  r = e.approx(60, CORE_INFTY);
  timer.stop();

  cout << "r=" << r << endl;
  cout << "it took " << timer.get_mseconds()<< " mseconds." << endl;

  return 0;
}
Ejemplo n.º 3
0
// floor(e, sub) returns the floor(e), and puts the
//      remainder into sub.
BigInt floor(const Expr& e, Expr &sub) {
  if (e==0) {
	  return 0;
  }
  BigInt f = e.approx(CORE_INFTY, 2).BigIntValue();
  sub = e-f;
  // Adjustment
  if (sub<0)
    ++sub, --f;
  if (sub>=1)
    --sub, ++f;
  assert(sub >=0 && sub<1); // got an assertion error? (Chee 3/24/04)
  return f;
}