Add mod (and setmod) operators

This commit is contained in:
Nicolas Williams committed 2013-06-21 15:27:34 -05:00
1 parent dc2fe63e42
commit 3403d07912
4 files changed
+38 -4

No files matched your search

+10
View File
@@ -119,6 +119,15 @@ static jv f_divide(jv input, jv a, jv b) {
}
}
static jv f_mod(jv input, jv a, jv b) {
jv_free(input);
if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
} else {
return type_error2(a, b, "cannot be divided");
}
}
static jv f_equal(jv input, jv a, jv b) {
jv_free(input);
return jv_bool(jv_equal(a, b));
@@ -476,6 +485,7 @@ static const struct cfunction function_list[] = {
{(cfunction_ptr)f_minus, "_minus", 3},
{(cfunction_ptr)f_multiply, "_multiply", 3},
{(cfunction_ptr)f_divide, "_divide", 3},
{(cfunction_ptr)f_mod, "_mod", 3},
{(cfunction_ptr)f_tonumber, "tonumber", 1},
{(cfunction_ptr)f_tostring, "tostring", 1},
{(cfunction_ptr)f_keys, "keys", 1},