1 Star 0 Fork 0

zhouxs1023/eigenmath_pratt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
floor.cpp 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
Calin Barbat 提交于 2018-02-24 10:52 . Initial commit.
#include "stdafx.h"
#include "defs.h"
void
eval_floor(void)
{
push(cadr(p1));
eval();
yfloor();
}
void
yfloor(void)
{
save();
yyfloor();
restore();
}
void
yyfloor(void)
{
double d;
p1 = pop();
if (!isnum(p1)) {
push_symbol(FLOOR);
push(p1);
list(2);
return;
}
if (isdouble(p1)) {
d = floor(p1->u.d);
push_double(d);
return;
}
if (isinteger(p1)) {
push(p1);
return;
}
p3 = alloc();
p3->k = NUM;
p3->u.q.a = mdiv(p1->u.q.a, p1->u.q.b);
p3->u.q.b = mint(1);
push(p3);
if (isnegativenumber(p1)) {
push_integer(-1);
add();
}
}
#if SELFTEST
static const char *s[] = {
"floor(a)",
"floor(a)",
"floor(a+b)",
"floor(a+b)",
"floor(5/2)",
"2",
"floor(4/2)",
"2",
"floor(3/2)",
"1",
"floor(2/2)",
"1",
"floor(1/2)",
"0",
"floor(0/2)",
"0",
"floor(-1/2)",
"-1",
"floor(-2/2)",
"-1",
"floor(-3/2)",
"-2",
"floor(-4/2)",
"-2",
"floor(-5/2)",
"-3",
"floor(5/2.0)",
"2",
"floor(4/2.0)",
"2",
"floor(3/2.0)",
"1",
"floor(2/2.0)",
"1",
"floor(1/2.0)",
"0",
"floor(0.0)",
"0",
"floor(-1/2.0)",
"-1",
"floor(-2/2.0)",
"-1",
"floor(-3/2.0)",
"-2",
"floor(-4/2.0)",
"-2",
"floor(-5/2.0)",
"-3",
};
void
test_floor(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zhouxs1023/eigenmath_pratt.git
git@gitee.com:zhouxs1023/eigenmath_pratt.git
zhouxs1023
eigenmath_pratt
eigenmath_pratt
master

搜索帮助