This commit is contained in:
William Langford committed 2015-03-23 22:11:55 -04:00
1 parent ccfba00178
commit 0f7759f831
1 file changed
+3
+3
View File
@@ -218,6 +218,9 @@ static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
static jv f_mod(jq_state *jq, jv input, jv a, jv b) {
jv_free(input);
if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
if ((intmax_t)jv_number_value(b) == 0) {
return jv_invalid_with_msg(jv_string("Cannot mod by zero."));
}
return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
} else {
return type_error2(a, b, "cannot be divided");