Beispiel #1
0
void
mpd_canonical(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
{
	mpd_copy(result, a, ctx);
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	mpd_context_t ctx;
	mpd_t *x0, *y0;
	mpd_t *sqrt_2, *xstep, *ystep;
	uint32_t prec = 19;

	int iter = 1000;
	int points[40][80];
	int i, j;
	clock_t start_clock, end_clock;


	if (argc != 3) {
		fprintf(stderr, "usage: ./bench prec iter\n");
		exit(1);
	}
	prec = strtoul(argv[1], NULL, 10);
	iter = strtol(argv[2], NULL, 10);

	mpd_init(&ctx, prec);
	/* no more MPD_MINALLOC changes after here */

	sqrt_2 = mpd_new(&ctx);
	xstep = mpd_new(&ctx);
	ystep = mpd_new(&ctx);
	x0 = mpd_new(&ctx);
	y0 = mpd_new(&ctx);

	mpd_set_u32(sqrt_2, 2, &ctx);
	mpd_sqrt(sqrt_2, sqrt_2, &ctx);
	mpd_div_u32(xstep, sqrt_2, 40, &ctx);
	mpd_div_u32(ystep, sqrt_2, 20, &ctx);

	start_clock = clock();
	mpd_copy(y0, sqrt_2, &ctx);
	for (i = 0; i < 40; i++) {
		mpd_copy(x0, sqrt_2, &ctx);
		mpd_set_negative(x0);
		for (j = 0; j < 80; j++) {
			points[i][j] = color_point(x0, y0, iter, &ctx);
			mpd_add(x0, x0, xstep, &ctx);
		}
		mpd_sub(y0, y0, ystep, &ctx);
	}
	end_clock = clock();

#ifdef BENCH_VERBOSE
	for (i = 0; i < 40; i++) {
		for (j = 0; j < 80; j++) {
			if (points[i][j] == iter) {
				putchar('*');
			}
			else if (points[i][j] >= 10) {
				putchar('+');
			}
			else if (points[i][j] >= 5) {
				putchar('.');
			}
			else {
				putchar(' ');
			}
		}
		putchar('\n');
	}
	putchar('\n');
#endif

	printf("time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC);

	mpd_del(x0);
	mpd_del(y0);
	mpd_del(sqrt_2);
	mpd_del(xstep);
	mpd_del(ystep);

	return 0;
}