• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pop_number函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pop_number函数的典型用法代码示例。如果您正苦于以下问题:C++ pop_number函数的具体用法?C++ pop_number怎么用?C++ pop_number使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pop_number函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: bmod

static void
bmod(void)
{
	struct number *a, *b, *r;
	BN_CTX *ctx;
	u_int scale;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	r = new_number();
	scale = max(a->scale, b->scale);
	r->scale = scale;

	if (BN_is_zero(a->number))
		warnx("remainder by zero");
	else {
		normalize(a, scale);
		normalize(b, scale);

		ctx = BN_CTX_new();
		bn_checkp(ctx);
		bn_check(BN_mod(r->number, b->number, a->number, ctx));
		BN_CTX_free(ctx);
	}
	push_number(r);
	free_number(a);
	free_number(b);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:35,代码来源:bcode.c


示例2: eval

void eval(stack **n_stack, stack **o_stack, double *x, double *y){
	//Using easier names
	char op=top_operator(*o_stack);
	double n1, n2;
		
	//Checking the different cases for the top of the stack
	if(op=='='){
		pop_operator(&(*o_stack));
		if(pop_operator(&(*o_stack))=='x')
			*x=top_number(*n_stack);
		else
			*y=top_number(*n_stack);
	}
	else if(op=='x'){
		pop_operator(&(*o_stack));
		push_number(*x, &(*n_stack));
	}
	else if(op=='y'){
		pop_operator(&(*o_stack));
		push_number(*y, &(*n_stack));
	}
	else{//Push the computed result into the n_stack
		n1=pop_number(&(*n_stack));
		n2=pop_number(&(*n_stack));
		op=pop_operator(&(*o_stack));
		push_number(compute(n1, op, n2), &(*n_stack));
	}
}
开发者ID:srijanshetty,项目名称:DS,代码行数:28,代码来源:expression_evaluation.c


示例3: bsub

static void
bsub(void)
{
	struct number	*a, *b, *r;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	r = new_number();

	r->scale = max(a->scale, b->scale);
	if (r->scale > a->scale)
		normalize(a, r->scale);
	else if (r->scale > b->scale)
		normalize(b, r->scale);
	bn_check(BN_sub(r->number, b->number, a->number));
	push_number(r);
	free_number(a);
	free_number(b);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:26,代码来源:bcode.c


示例4: bdivmod

static void
bdivmod(void)
{
	struct number *a, *b, *frac, *quotient, *rdiv, *remainder;
	BN_CTX *ctx;
	u_int scale;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	rdiv = new_number();
	quotient = new_number();
	remainder = new_number();
	scale = max(a->scale, b->scale);
	rdiv->scale = 0;
	remainder->scale = scale;
	quotient->scale = bmachine.scale;
	scale = max(a->scale, b->scale);

	if (BN_is_zero(a->number))
		warnx("divide by zero");
	else {
		normalize(a, scale);
		normalize(b, scale);

		ctx = BN_CTX_new();
		bn_checkp(ctx);
		/*
		 * Unlike other languages' divmod operations, dc is specified
		 * to return the remainder and the full quotient, rather than
		 * the remainder and the floored quotient.  bn(3) has no
		 * function to calculate both.  So we'll use BN_div to get the
		 * remainder and floored quotient, then calculate the full
		 * quotient from those.
		 *
		 * quotient = rdiv + remainder / divisor
		 */
		bn_check(BN_div(rdiv->number, remainder->number,
		    b->number, a->number, ctx));
		frac = div_number(remainder, a, bmachine.scale);
		normalize(rdiv, bmachine.scale);
		normalize(remainder, scale);
		bn_check(BN_add(quotient->number, rdiv->number, frac->number));
		free_number(frac);
		BN_CTX_free(ctx);
	}
	push_number(quotient);
	push_number(remainder);
	free_number(rdiv);
	free_number(a);
	free_number(b);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:58,代码来源:bcode.c


示例5: compare

static void
compare(enum bcode_compare type)
{
	int		index, elseindex;
	struct number	*a, *b;
	bool		ok;
	struct value	*v;

	elseindex = NO_ELSE;
	index = readreg();
	if (readch() == 'e')
		elseindex = readreg();
	else
		unreadch();

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	ok = compare_numbers(type, a, b);

	if (!ok && elseindex != NO_ELSE)
		index = elseindex;

	if (index >= 0 && (ok || (!ok && elseindex != NO_ELSE))) {
		v = stack_tos(&bmachine.reg[index]);
		if (v == NULL)
			warnx("register '%c' (0%o) is empty", index, index);
		else {
			switch(v->type) {
			case BCODE_NONE:
				warnx("register '%c' (0%o) is empty",
				    index, index);
				break;
			case BCODE_NUMBER:
				warn("eval called with non-string argument");
				break;
			case BCODE_STRING:
				eval_string(bstrdup(v->u.string));
				break;
			}
		}
	}
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:49,代码来源:bcode.c


示例6: load_array

static void
load_array(void)
{
	struct number *inumber, *n;
	struct stack *stack;
	struct value *v;
	struct value copy;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number))
			warnx("negative idx");
		else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX)
			warnx("idx too big");
		else {
			stack = &bmachine.reg[reg];
			v = frame_retrieve(stack, idx);
			if (v == NULL || v->type == BCODE_NONE) {
				n = new_number();
				bn_check(BN_zero(n->number));
				push_number(n);
			}
			else
				push(stack_dup_value(v, &copy));
		}
		free_number(inumber);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:34,代码来源:bcode.c


示例7: load_array

static void
load_array(void)
{
	int			reg;
	struct number		*inumber, *n;
	u_long			index;
	struct stack		*stack;
	struct value		*v, copy;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		index = get_ulong(inumber);
		if (BN_cmp(inumber->number, &zero) < 0)
			warnx("negative index");
		else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX)
			warnx("index too big");
		else {
			stack = &bmachine.reg[reg];
			v = frame_retrieve(stack, index);
			if (v == NULL) {
				n = new_number();
				bn_check(BN_zero(n->number));
				push_number(n);
			}
			else
				push(stack_dup_value(v, &copy));
		}
		free_number(inumber);
	}
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:33,代码来源:bcode.c


示例8: store_array

static void
store_array(void)
{
	struct number *inumber;
	struct value *value;
	struct stack *stack;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		value = pop();
		if (value == NULL) {
			free_number(inumber);
			return;
		}
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number)) {
			warnx("negative idx");
			stack_free_value(value);
		} else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX) {
			warnx("idx too big");
			stack_free_value(value);
		} else {
			stack = &bmachine.reg[reg];
			frame_assign(stack, idx, value);
		}
		free_number(inumber);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:33,代码来源:bcode.c


示例9: store_array

static void
store_array(void)
{
	int			reg;
	struct number		*inumber;
	u_long			index;
	struct value		*value;
	struct stack		*stack;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		value = pop();
		if (value == NULL) {
			free_number(inumber);
			return;
		}
		index = get_ulong(inumber);
		if (BN_cmp(inumber->number, &zero) < 0) {
			warnx("negative index");
			stack_free_value(value);
		} else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX) {
			warnx("index too big");
			stack_free_value(value);
		} else {
			stack = &bmachine.reg[reg];
			frame_assign(stack, index, value);
		}
		free_number(inumber);
	}
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:33,代码来源:bcode.c


示例10: lesseq_numbers

static void
lesseq_numbers(void)
{
	struct number *a, *b, *r;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}
	r = new_number();
	bn_check(BN_set_word(r->number,
	    compare_numbers(BCODE_NOT_GREATER, a, b) ? 1 : 0));
	push_number(r);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:18,代码来源:bcode.c


示例11: equal_numbers

static void
equal_numbers(void)
{
	struct number *a, *b, *r;

	a = pop_number();
	if (a == NULL) {
		return;
	}
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}
	r = new_number();
	bn_check(BN_set_word(r->number,
	    compare_numbers(BCODE_EQUAL, a, b) ? 1 : 0));
	push_number(r);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:19,代码来源:bcode.c


示例12: bdiv

static void
bdiv(void)
{
	struct number *a, *b, *r;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	r = div_number(b, a, bmachine.scale);

	push_number(r);
	free_number(a);
	free_number(b);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:20,代码来源:bcode.c


示例13: bdivmod

static void
bdivmod(void)
{
	struct number	*a, *b;
	struct number	*rdiv, *rmod;
	u_int		scale;
	BN_CTX		*ctx;

	a = pop_number();
	if (a == NULL) {
		return;
	}
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	rdiv = new_number();
	rmod = new_number();
	rdiv->scale = bmachine.scale;
	rmod->scale = max(b->scale, a->scale + bmachine.scale);
	scale = max(a->scale, b->scale);

	if (BN_is_zero(a->number))
		warnx("divide by zero");
	else {
		normalize(a, scale);
		normalize(b, scale + bmachine.scale);

		ctx = BN_CTX_new();
		bn_checkp(ctx);
		bn_check(BN_div(rdiv->number, rmod->number,
		    b->number, a->number, ctx));
		BN_CTX_free(ctx);
	}
	push_number(rdiv);
	push_number(rmod);
	free_number(a);
	free_number(b);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:41,代码来源:bcode.c


示例14: not

static void
not(void)
{
	struct number *a;

	a = pop_number();
	if (a == NULL)
		return;
	a->scale = 0;
	bn_check(BN_set_word(a->number, BN_get_word(a->number) ? 0 : 1));
	push_number(a);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:12,代码来源:bcode.c


示例15: bmul

static void
bmul(void)
{
	struct number *a, *b, *r;

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	r = new_number();
	bmul_number(r, a, b, bmachine.scale);

	push_number(r);
	free_number(a);
	free_number(b);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:21,代码来源:bcode.c


示例16: bmul

static void
bmul(void)
{
	struct number	*a, *b;
	struct number	*r;

	a = pop_number();
	if (a == NULL) {
		return;
	}
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	r = new_number();
	bmul_number(r, a, b);

	push_number(r);
	free_number(a);
	free_number(b);
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:23,代码来源:bcode.c


示例17: set_obase

static void
set_obase(void)
{
	struct number *n;
	u_long base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != ULONG_MAX && base > 1 && base <= UINT_MAX)
			bmachine.obase = (u_int)base;
		else
			warnx("output base must be a number greater than 1");
		free_number(n);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:16,代码来源:bcode.c


示例18: set_obase

static void
set_obase(void)
{
	struct number	*n;
	u_long		base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != BN_MASK2 && base > 1)
			bmachine.obase = base;
		else
			warnx("output base must be a number greater than 1");
		free_number(n);
	}
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:16,代码来源:bcode.c


示例19: bsqrt

static void
bsqrt(void)
{
	struct number	*n;
	struct number	*r;
	BIGNUM		*x, *y;
	u_int		scale, onecount;
	BN_CTX		*ctx;

	onecount = 0;
	n = pop_number();
	if (n == NULL) {
		return;
	}
	if (BN_is_zero(n->number)) {
		r = new_number();
		push_number(r);
	} else if (BN_is_negative(n->number))
		warnx("square root of negative number");
	else {
		scale = max(bmachine.scale, n->scale);
		normalize(n, 2*scale);
		x = BN_dup(n->number);
		bn_checkp(x);
		bn_check(BN_rshift(x, x, BN_num_bits(x)/2));
		y = BN_new();
		bn_checkp(y);
		ctx = BN_CTX_new();
		bn_checkp(ctx);
		for (;;) {
			bn_checkp(BN_copy(y, x));
			bn_check(BN_div(x, NULL, n->number, x, ctx));
			bn_check(BN_add(x, x, y));
			bn_check(BN_rshift1(x, x));
			if (bsqrt_stop(x, y, &onecount))
				break;
		}
		r = bmalloc(sizeof(*r));
		r->scale = scale;
		r->number = y;
		BN_free(x);
		BN_CTX_free(ctx);
		push_number(r);
	}

	free_number(n);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:47,代码来源:bcode.c


示例20: set_ibase

static void
set_ibase(void)
{
	struct number *n;
	u_long base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != ULONG_MAX && 2 <= base && base <= 16)
			bmachine.ibase = (u_int)base;
		else
			warnx("input base must be a number between 2 and 16 "
			    "(inclusive)");
		free_number(n);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:17,代码来源:bcode.c



注:本文中的pop_number函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pop_stack函数代码示例发布时间:2022-05-30
下一篇:
C++ pop_n_elems函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap