diff options
author | Nicolas Williams <nico@cryptonector.com> | 2013-06-17 20:21:37 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2013-06-21 15:27:34 -0500 |
commit | 3403d07912ceb49aff1402ba5b23ecc5f893d608 (patch) | |
tree | f9ebc57dc0b903f8742b2f2b559fa08e1c4b8d80 /builtin.c | |
parent | dc2fe63e42341d1d34cc8e36694b98b9dda16c52 (diff) |
Add mod (and setmod) operators
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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}, |