📄 math.cpp
字号:
} else {
not_a_number();
return;
}
if (p2.flong->test_long(&l)) {
d2 = (double) l;
} else if (p2.node->has_tag(TAG_DOUBLE)) {
d2 = p2.fdouble->get_double();
} else {
not_a_number();
return;
}
pop();
replace(FDouble::create(pow(d1, d2), this));
} else not_a_number();
}
void Machine::op_div()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 p1val, p2val;
FVal res = NULL;
if (p1.node && p2.node) {
if (p1.flong->test_long(&p1val)) {
if (p2.flong->test_long(&p2val)) {
res = FLong::create(p1val / p2val, this);
} else if (p2.node->has_tag(TAG_DOUBLE)) {
res = FDouble::create(p1val / p2.fdouble->get_double(), this);
} else not_a_number();
} else if (p1.node->has_tag(TAG_DOUBLE)) {
if (p2.flong->test_long(&p2val)) {
res = FDouble::create(p1.fdouble->get_double() / p2val, this);
} else if (p2.node->has_tag(TAG_DOUBLE)) {
res = FDouble::create(p1.fdouble->get_double() /
p2.fdouble->get_double(), this);
} else not_a_number();
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_rem()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 p1val, p2val;
FVal res = NULL;
if (p1.flong->test_long(&p1val) && p2.flong->test_long(&p2val)) {
res = FLong::create(p1val % p2val, this);
pop();
replace(res);
return;
}
not_a_number();
pop();
}
void Machine::op_min()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
res = FLong::create(min(i1, i2), this);
} else if (p2.fdouble->test_double(&d2)) {
res = FDouble::create(min(i1, d2), this);
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
res = FDouble::create(min(d1, i2), this);
} else if (p2.fdouble->test_double(&d2)) {
res = FDouble::create(min(d1, d2), this);
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_max()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
res = FLong::create(max(i1, i2), this);
} else if (p2.fdouble->test_double(&d2)) {
res = FDouble::create(max(i1, d2), this);
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
res = FDouble::create(max(d1, i2), this);
} else if (p2.fdouble->test_double(&d2)) {
res = FDouble::create(max(d1, d2), this);
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_logand()
{
FLong_ptr p1 = read_next_tos().flong;
FLong_ptr p2 = read_tos().flong;
int64 i1, i2;
FVal res = NULL;
if (p1->test_long(&i1) && p2->test_long(&i2)) {
res = FLong::create((long) (i1 & i2), this);
}
pop();
replace(res);
}
void Machine::op_rshift()
{
FLong_ptr p1 = read_next_tos().flong;
FLong_ptr p2 = read_tos().flong;
int64 i1, i2;
FVal res = NULL;
if (p1->test_long(&i1) && p2->test_long(&i2)) {
res = FLong::create(i1 >> i2, this);
} else p1->get_long_error(this);
pop();
replace(res);
}
void Machine::op_lshift()
{
FLong_ptr p1 = read_next_tos().flong;
FLong_ptr p2 = read_tos().flong;
int64 i1, i2;
FVal res = NULL;
if (p1->test_long(&i1) && p2->test_long(&i2)) {
res = FLong::create(i1 << i2, this);
} else p1->get_long_error(this);
pop();
replace(res);
}
void Machine::op_logior()
{
FLong_ptr p1 = read_next_tos().flong;
FLong_ptr p2 = read_tos().flong;
int64 i1, i2;
FVal res = NULL;
if (p1->test_long(&i1) && p2->test_long(&i2)) {
res = FLong::create((long) (i1 | i2), this);
}
pop();
replace(res);
}
void Machine::op_logxor()
{
FLong_ptr p1 = read_next_tos().flong;
FLong_ptr p2 = read_tos().flong;
int64 i1, i2;
FVal res = NULL;
if (p1->test_long(&i1) && p2->test_long(&i2)) {
res = FLong::create(i1 ^ i2, this);
}
pop();
replace(res);
}
void Machine::op_less()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
if (i1 < i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (i1 < d2) res = s_true;
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
if (d1 < i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (d1 < d2) res = s_true;
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_lesseql()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
if (i1 <= i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (i1 <= d2) res = s_true;
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
if (d1 <= i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (d1 <= d2) res = s_true;
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_noteql()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
if (i1 != i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (i1 != d2) res = s_true;
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
if (d1 != i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (d1 != d2) res = s_true;
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_gtreql()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
if (i1 >= i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (i1 >= d2) res = s_true;
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
if (d1 >= i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (d1 >= d2) res = s_true;
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
void Machine::op_gtr()
{
FUnion p1 = read_next_tos();
FUnion p2 = read_tos();
int64 i1, i2;
double d1, d2;
FVal res = NULL;
if (p1.flong->test_long(&i1)) {
if (p2.flong->test_long(&i2)) {
if (i1 > i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (i1 > d2) res = s_true;
} else not_a_number();
} else if (p1.fdouble->test_double(&d1)) {
if (p2.flong->test_long(&i2)) {
if (d1 > i2) res = s_true;
} else if (p2.fdouble->test_double(&d2)) {
if (d1 > d2) res = s_true;
} else not_a_number();
} else not_a_number();
pop();
replace(res);
}
/* NO OPERANDS */
void Machine::op_random() { illegal_instruction(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -