diff --git a/m-algo.h b/m-algo.h index 137676f5..7b93ce1e 100644 --- a/m-algo.h +++ b/m-algo.h @@ -935,6 +935,7 @@ #define ALGOI_REDUCE_AND(a,b) ((a) &= (b)) #define ALGOI_REDUCE_OR(a,b) ((a) |= (b)) #define ALGOI_REDUCE_SUM(a,b) ((a) += (b)) +#define ALGOI_REDUCE_PRODUCT(a,b) ((a) *= (b)) /* Return the method associated to a reduce operation. It returns the special function handler if function is and, or, sum or add. @@ -945,7 +946,11 @@ M_IF(M_KEYWORD_P(or, reduceFunc)) \ (ALGOI_REDUCE_OR, \ M_IF(M_KEYWORD_P(sum, reduceFunc)) \ - (ALGOI_REDUCE_SUM, reduceFunc) \ + (ALGOI_REDUCE_SUM, \ + M_IF(M_KEYWORD_P(product, reduceFunc)) \ + (ALGOI_REDUCE_PRODUCT, \ + reduceFunc) \ + ) \ ) \ ) diff --git a/m-core.h b/m-core.h index 70519401..302bc90a 100644 --- a/m-core.h +++ b/m-core.h @@ -817,6 +817,8 @@ extern void m_no_default_function(void) __attribute__((error("The requested op #define M_PATTERN_sum_add , #define M_PATTERN_add_add , #define M_PATTERN_add_sum , +#define M_PATTERN_product_product , +#define M_PATTERN_product_mul , #define M_PATTERN_bool_bool , diff --git a/tests/test-malgo.c b/tests/test-malgo.c index 09ce1aa8..cdf0ca4d 100644 --- a/tests/test-malgo.c +++ b/tests/test-malgo.c @@ -502,6 +502,8 @@ static void test_extract(void) assert (dst == 0); ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), or); assert (dst == 127); + ALGO_REDUCE(dst, a, ARRAY_OPLIST(array_int), product); + assert (dst == 0); array_int_clear(a); list_int_clear(l);