1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-23 11:47:40 +00:00

Port some cfunctions in math.c to corelib as

assembled functions.
This commit is contained in:
Calvin Rose
2018-07-08 23:10:02 -04:00
parent 423ebc937a
commit b860b0a3c5
5 changed files with 126 additions and 122 deletions

View File

@@ -71,19 +71,6 @@ int dst_real(DstArgs args) {
return 0;
}
int dst_bnot(DstArgs args) {
if (args.n != 1) {
*args.ret = dst_cstringv("expected 1 argument");
return 1;
}
if (!dst_checktype(args.v[0], DST_INTEGER)) {
*args.ret = dst_cstringv("expected integer");
return 1;
}
*args.ret = dst_wrap_integer(~dst_unwrap_integer(args.v[0]));
return 0;
}
int dst_remainder(DstArgs args) {
DST_FIXARITY(args, 2);
if (dst_checktype(args.v[0], DST_INTEGER) &&
@@ -137,44 +124,6 @@ int dst_##name(DstArgs args) {\
DST_DEFINE_MATH2OP(atan2, atan2)
DST_DEFINE_MATH2OP(pow, pow)
/* Comparison */
#define DST_DEFINE_COMPARATOR(name, pred)\
static int dst_##name(DstArgs args) {\
int32_t i;\
for (i = 0; i < args.n - 1; i++) {\
if (dst_compare(args.v[i], args.v[i+1]) pred) {\
DST_RETURN_FALSE(args);\
}\
}\
DST_RETURN_TRUE(args);\
}
DST_DEFINE_COMPARATOR(ascending, >= 0)
DST_DEFINE_COMPARATOR(descending, <= 0)
DST_DEFINE_COMPARATOR(notdescending, > 0)
DST_DEFINE_COMPARATOR(notascending, < 0)
/* Boolean logic */
static int dst_strict_equal(DstArgs args) {
int32_t i;
for (i = 0; i < args.n - 1; i++) {
if (!dst_equals(args.v[i], args.v[i+1])) {
DST_RETURN_FALSE(args);
}
}
DST_RETURN_TRUE(args);
}
static int dst_strict_notequal(DstArgs args) {
int32_t i;
for (i = 0; i < args.n - 1; i++) {
if (!dst_equals(args.v[i], args.v[i+1])) {
DST_RETURN_TRUE(args);
}
}
DST_RETURN_FALSE(args);
}
static int dst_not(DstArgs args) {
DST_FIXARITY(args, 1);
DST_RETURN_BOOLEAN(args, !dst_truthy(args.v[0]));
@@ -203,19 +152,12 @@ DEF_NUMERIC_COMP(neq, !=)
static const DstReg cfuns[] = {
{"%", dst_remainder},
{"=", dst_strict_equal},
{"not=", dst_strict_notequal},
{"order<", dst_ascending},
{"order>", dst_descending},
{"order<=", dst_notdescending},
{"order>=", dst_notascending},
{"==", dst_numeric_eq},
{"not==", dst_numeric_neq},
{"<", dst_numeric_lt},
{">", dst_numeric_gt},
{"<=", dst_numeric_lte},
{">=", dst_numeric_gte},
{"~", dst_bnot},
{"not", dst_not},
{"int", dst_int},
{"real", dst_real},