本文整理汇总了C++中pop_number函数的典型用法代码示例。如果您正苦于以下问题:C++ pop_number函数的具体用法?C++ pop_number怎么用?C++ pop_number使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop_number函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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));
}
}
示例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);
}
示例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);
}
示例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;
}
}
}
}
示例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, ©));
}
free_number(inumber);
}
}
示例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, ©));
}
free_number(inumber);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}