コード例 #1
0
ファイル: bench.c プロジェクト: AndreRH/mingw-w64
/*
 * Example from: http://en.wikipedia.org/wiki/Mandelbrot_set
 *
 * Escape time algorithm for drawing the set:
 *
 * Point x0, y0 is deemed to be in the Mandelbrot set if the return
 * value is maxiter. Lower return values indicate how quickly points
 * escaped and can be used for coloring.
 */
int
color_point(mpd_t *x0, mpd_t *y0, int maxiter, mpd_context_t *ctx)
{
	mpd_t *x, *y, *sq_x, *sq_y;
	mpd_t *two, *four, *c;
	int i;

	x = mpd_new(ctx);
	y = mpd_new(ctx);
	mpd_set_u32(x, 0, ctx);
	mpd_set_u32(y, 0, ctx);

	sq_x = mpd_new(ctx);
	sq_y = mpd_new(ctx);
	mpd_set_u32(sq_x, 0, ctx);
	mpd_set_u32(sq_y, 0, ctx);

	two = mpd_new(ctx);
	four = mpd_new(ctx);
	mpd_set_u32(two, 2, ctx);
	mpd_set_u32(four, 4, ctx);

	c = mpd_new(ctx);
	mpd_set_u32(c, 0, ctx);

	for (i = 0; i < maxiter && mpd_cmp(c, four, ctx) <= 0; i++) {

		mpd_mul(y, x, y, ctx);
		mpd_mul(y, y, two, ctx);
		mpd_add(y, y, y0, ctx);

		mpd_sub(x, sq_x, sq_y, ctx);
		mpd_add(x, x, x0, ctx);

		mpd_mul(sq_x, x, x, ctx);
		mpd_mul(sq_y, y, y, ctx);
		mpd_add(c, sq_x, sq_y, ctx);
	}

	mpd_del(x);
	mpd_del(y);
	mpd_del(sq_x);
	mpd_del(sq_y);
	mpd_del(two);
	mpd_del(four);
	mpd_del(c);

	return i;
}
コード例 #2
0
int update_user_balance(bool real, uint32_t user_id, const char *asset, const char *business, uint64_t business_id, mpd_t *change, json_t *detail)
{
    struct update_key key;
    key.user_id = user_id;
    strncpy(key.asset, asset, sizeof(key.asset));
    strncpy(key.business, business, sizeof(key.business));
    key.business_id = business_id;

    dict_entry *entry = dict_find(dict_update, &key);
    if (entry) {
        return -1;
    }

    mpd_t *result;
    mpd_t *abs_change = mpd_new(&mpd_ctx);
    mpd_abs(abs_change, change, &mpd_ctx);
    if (mpd_cmp(change, mpd_zero, &mpd_ctx) >= 0) {
        result = balance_add(user_id, BALANCE_TYPE_AVAILABLE, asset, abs_change);
    } else {
        result = balance_sub(user_id, BALANCE_TYPE_AVAILABLE, asset, abs_change);
    }
    mpd_del(abs_change);
    if (result == NULL)
        return -2;

    struct update_val val = { .create_time = current_timestamp() };
    dict_add(dict_update, &key, &val);

    if (real) {
        double now = current_timestamp();
        json_object_set_new(detail, "id", json_integer(business_id));
        char *detail_str = json_dumps(detail, 0);
        append_user_balance_history(now, user_id, asset, business, change, detail_str);
        free(detail_str);
        push_balance_message(now, user_id, asset, business, change);
    }

    return 0;
}
コード例 #3
0
ファイル: mpd.c プロジェクト: gap-packages/float
static Obj LT_MPD (Obj self, Obj fl, Obj fr)
{
  return mpd_cmp(GET_MPD(fl),GET_MPD(fr)) < 0 ? True : False;
}
コード例 #4
0
ファイル: mpd.c プロジェクト: gap-packages/float
static Obj EQ_MPD (Obj self, Obj fl, Obj fr)
{
  return mpd_cmp(GET_MPD(fr),GET_MPD(fl)) == 0 ? True : False;
}