diff --git a/Changelog b/Changelog
new file mode 100644
index 0000000..8d2d246
--- /dev/null
+++ b/Changelog
@@ -0,0 +1,4 @@
+1.0.1:
+
+ * Add a function to allocate memory for arrays of temporary values
+
diff --git a/Makefile b/Makefile
index d73250a..29c5d76 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
# if static=1 then compile the static library
STATIC=0
-VERSION=1.0
+VERSION=1.0.1
# products of the compilation
PROJECT_SO=libinum.so.$(VERSION)
diff --git a/doc/libinum-doc.html b/doc/libinum-doc.html
index e50e8f7..1486797 100644
--- a/doc/libinum-doc.html
+++ b/doc/libinum-doc.html
@@ -76,10 +76,10 @@
- libinum v1.0
+ libinum v1.0.1
- This is the official documentation for libinum, version 1.0.
+ This is the official documentation for libinum, version 1.0.1.
Table of contents
@@ -1262,6 +1262,35 @@
copy input
to the array pointed to by output
. Does not initialize *output
, so *output
must be initialized ahead of time, and its memory must be larger or equal to the length of input
. Returns LIBINUM_ERROR_SIZE_MISMATCH
if the memory of *output
is smaller than the length of input
.
+
+
+
+ int array_mpfr_alloc_tmps(unsigned int n, array_mpfr* array)
+
+
+
+ int array_2_mpfr_alloc_tmps(unsigned int n, array_2_mpfr* array)
+
+
+
+ int array_str_alloc_tmps(unsigned int n, array_str* array)
+
+
+
+ int array_polynomial_double_alloc_tmps(unsigned int n, array_polynomial_double* array)
+
+
+
+ int array_polynomial_ldouble_alloc_tmps(unsigned int n, array_polynomial_ldouble* array)
+
+
+
+ int array_polynomial_mpfr_alloc_tmps(unsigned int n, array_polynomial_mpfr* array)
+
+
+ Ensure that *array
has at least n
allocated values. If it has fewer, then allocate as many as needed.
+
+
diff --git a/doc/libinum-doc.php b/doc/libinum-doc.php
index 2daf429..d140ab2 100644
--- a/doc/libinum-doc.php
+++ b/doc/libinum-doc.php
@@ -76,10 +76,10 @@
-
libinum v1.0
+
libinum v1.0.1
- This is the official documentation for libinum, version 1.0.
+ This is the official documentation for libinum, version 1.0.1.
Table of contents
@@ -839,6 +839,22 @@
copy
input
to the array pointed to by
output
. Does not initialize
*output
, so
*output
must be initialized ahead of time, and its memory must be larger or equal to the length of
input
. Returns
LIBINUM_ERROR_SIZE_MISMATCH
if the memory of
*output
is smaller than the length of
input
.
+
+
+ int array_${TYPENAME}_alloc_tmps(unsigned int n, array_${TYPENAME}* array)
+
+ ");
+ }
+ ?>
+
+ Ensure that *array
has at least n
allocated values. If it has fewer, then allocate as many as needed.
+
+
diff --git a/src/array_2_mpfr.h b/src/array_2_mpfr.h
index afd99d9..35947ad 100644
--- a/src/array_2_mpfr.h
+++ b/src/array_2_mpfr.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE array_mpfr
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) array_mpfr_init(VAL, SIZE)
// free
#define ARRAY_VAL_FREE(VAL) array_mpfr_free(VAL)
// set values
diff --git a/src/array_base.c b/src/array_base.c
index a70bd86..f340d6c 100644
--- a/src/array_base.c
+++ b/src/array_base.c
@@ -247,3 +247,19 @@ int ARRAY_FUNC(print) (ARRAY_TYPENAME array){
return(0);
}
#endif
+
+// allocate memory for values until there are at least 'n' alloacted values
+#ifdef ARRAY_VAL_INIT
+int ARRAY_FUNC(alloc_tmps) (unsigned int n, ARRAY_TYPENAME* array){
+ unsigned int i;
+ // resize if needed
+ if(array->memorylength; ivalues+i, 2);
+ (array->length)++;
+ }
+ return(0);
+}
+#endif
diff --git a/src/array_base.h b/src/array_base.h
index b9de5d2..002ea08 100644
--- a/src/array_base.h
+++ b/src/array_base.h
@@ -76,3 +76,7 @@ int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2);
int ARRAY_FUNC(print) (ARRAY_TYPENAME array);
#endif
+// allocate memory for values until there are at least 'n' alloacted values
+#ifdef ARRAY_VAL_INIT
+int ARRAY_FUNC(alloc_tmps) (unsigned int n, ARRAY_TYPENAME* array);
+#endif
diff --git a/src/array_char.h b/src/array_char.h
index 6c95174..949b17a 100644
--- a/src/array_char.h
+++ b/src/array_char.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/array_double.h b/src/array_double.h
index 8d3c187..0a272d7 100644
--- a/src/array_double.h
+++ b/src/array_double.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/array_int.h b/src/array_int.h
index 9496b89..9eed317 100644
--- a/src/array_int.h
+++ b/src/array_int.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/array_ldouble.h b/src/array_ldouble.h
index d314906..b00d2af 100644
--- a/src/array_ldouble.h
+++ b/src/array_ldouble.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/array_mpfr.h b/src/array_mpfr.h
index 46bc54b..5994ddd 100644
--- a/src/array_mpfr.h
+++ b/src/array_mpfr.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE mpfr_t
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) mpfr_init(*(VAL))
// free
#define ARRAY_VAL_FREE(VAL) mpfr_clear(VAL)
// set values
diff --git a/src/array_polynomial_double.h b/src/array_polynomial_double.h
index d25e689..a90002b 100644
--- a/src/array_polynomial_double.h
+++ b/src/array_polynomial_double.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE polynomial_double
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_double_init(VAL, SIZE)
// free
#define ARRAY_VAL_FREE(VAL) polynomial_double_free(VAL)
// set values
diff --git a/src/array_polynomial_ldouble.h b/src/array_polynomial_ldouble.h
index 49c81cc..9ff6468 100644
--- a/src/array_polynomial_ldouble.h
+++ b/src/array_polynomial_ldouble.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE polynomial_ldouble
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_ldouble_init(VAL, SIZE)
// free
#define ARRAY_VAL_FREE(VAL) polynomial_ldouble_free(VAL)
// set values
diff --git a/src/array_polynomial_mpfr.h b/src/array_polynomial_mpfr.h
index 8cfe6e8..6e73265 100644
--- a/src/array_polynomial_mpfr.h
+++ b/src/array_polynomial_mpfr.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE polynomial_mpfr
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_mpfr_init(VAL, SIZE)
// free
#define ARRAY_VAL_FREE(VAL) polynomial_mpfr_free(VAL)
// set values
diff --git a/src/array_pthread_t.h b/src/array_pthread_t.h
index e200c5d..aafce6e 100644
--- a/src/array_pthread_t.h
+++ b/src/array_pthread_t.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/array_str.h b/src/array_str.h
index 2d35d1b..2df0bef 100644
--- a/src/array_str.h
+++ b/src/array_str.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
@@ -39,6 +40,8 @@ limitations under the License.
// type of values
#define ARRAY_VAL_TYPE array_char
+// init
+#define ARRAY_VAL_INIT(VAL, SIZE) array_char_init(VAL, SIZE)
// free
#define ARRAY_VAL_FREE(VAL) array_char_free(VAL)
// set values
diff --git a/src/array_uint.h b/src/array_uint.h
index b3cec85..aaa195f 100644
--- a/src/array_uint.h
+++ b/src/array_uint.h
@@ -23,6 +23,7 @@ limitations under the License.
#undef ARRAY_TYPENAME
#undef ARRAY_FUNC
#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_INIT
#undef ARRAY_VAL_FREE
#undef ARRAY_VAL_SET
#undef ARRAY_VAL_CPY
diff --git a/src/integral_base.c b/src/integral_base.c
index da3f05a..e743191 100644
--- a/src/integral_base.c
+++ b/src/integral_base.c
@@ -254,16 +254,8 @@ int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*fun
return(LIBINUM_ERROR_SIZE_MISMATCH);
}
- // allocate tmps if needed
- if(tmps->memory<4){
- // no need to resize since the values should not be kept
- INTEGRAL_FLOATARRAY_FUNC(free)(*tmps);
- INTEGRAL_FLOATARRAY_FUNC(init)(tmps, 4);
- }
- for (i=tmps->length;i<4;i++){
- INTEGRAL_FLOAT_INIT(tmps->values[i]);
- (tmps->length)++;
- }
+ // allocate tmp values if needed
+ INTEGRAL_FLOATARRAY_FUNC(alloc_tmps)(4, tmps);
// init to 0
INTEGRAL_FLOAT_SET_UI(*out, 0);