Beispiel #1
0
static Obj LQUO_MPD(Obj self, Obj fl, Obj fr)
{
  mp_prec_t precl = mpd_get_prec(GET_MPD(fl)),
    precr = mpd_get_prec(GET_MPD(fr));
  
  Obj g = NEW_MPD(precl > precr ? precl : precr);
  mpd_div (MPD_OBJ(g), GET_MPD(fr), GET_MPD(fl), MPD_RNDNN);
  return g;
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	mpd_context_t ctx;
	mpd_t *a, *b;
	mpd_t *result;
	char *rstring;
	char status_str[MPD_MAX_FLAG_STRING];
	clock_t start_clock, end_clock;

	if (argc != 3) {
		fprintf(stderr, "div: usage: ./div x y\n");
		exit(1);
	}

	mpd_init(&ctx, 38);
	ctx.traps = 0;

	result = mpd_new(&ctx);
	a = mpd_new(&ctx);
	b = mpd_new(&ctx);
	mpd_set_string(a, argv[1], &ctx);
	mpd_set_string(b, argv[2], &ctx);

	start_clock = clock();
	mpd_div(result, a, b, &ctx);
	end_clock = clock();
	fprintf(stderr, "time: %f\n\n",
	           (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC);

	rstring = mpd_to_sci(result, 1);
	mpd_snprint_flags(status_str, MPD_MAX_FLAG_STRING, ctx.status);
	printf("%s  %s\n", rstring, status_str);

	mpd_del(a);
	mpd_del(b);
	mpd_del(result);
	mpd_free(rstring);

	return 0;
}