From 439eaf89eef8812bcc43be21179d1dd8b06d50a3 Mon Sep 17 00:00:00 2001 From: Thomas Legris Date: Fri, 29 Apr 2011 14:01:54 +0200 Subject: [PATCH] Add openscop_vector_mul_scalar function --- include/openscop/vector.h | 1 + source/vector.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/openscop/vector.h b/include/openscop/vector.h index 2bf7033..2f38cdf 100644 --- a/include/openscop/vector.h +++ b/include/openscop/vector.h @@ -108,6 +108,7 @@ void openscop_vector_free(openscop_vector_p); * Processing functions * *****************************************************************************/ openscop_vector_p openscop_vector_add_scalar(openscop_vector_p, int); +openscop_vector_p openscop_vector_mul_scalar(openscop_vector_p, int); openscop_vector_p openscop_vector_add(openscop_vector_p, openscop_vector_p); openscop_vector_p openscop_vector_sub(openscop_vector_p, openscop_vector_p); void openscop_vector_tag_inequality(openscop_vector_p); diff --git a/source/vector.c b/source/vector.c index 7dc7b60..78da98e 100644 --- a/source/vector.c +++ b/source/vector.c @@ -370,4 +370,23 @@ openscop_vector_equal(openscop_vector_p v1, openscop_vector_p v2) } +/** + * openscop_vector_mul_scalar function: + * this function returns a new vector corresponding to the one provided + * as parameter with each entry multiplied by a scalar. + * \param v The vector to multiply. + * \param scalar The scalar coefficient. + * \return A new vector corresponding to scalar * v. + */ +openscop_vector_p openscop_vector_mul_scalar(openscop_vector_p v, + int scalar) +{ + int i; + openscop_vector_p result = openscop_vector_malloc(v->size); + + for(i = 0; i < v->size; i++) + SCOPINT_multo(result->v[i], scalar, v->v[i]); + + return result; +} -- 2.11.4.GIT