Ian Jauslin
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array_2_mpfr.h3
-rw-r--r--src/array_base.c16
-rw-r--r--src/array_base.h4
-rw-r--r--src/array_char.h1
-rw-r--r--src/array_double.h1
-rw-r--r--src/array_int.h1
-rw-r--r--src/array_ldouble.h1
-rw-r--r--src/array_mpfr.h3
-rw-r--r--src/array_polynomial_double.h3
-rw-r--r--src/array_polynomial_ldouble.h3
-rw-r--r--src/array_polynomial_mpfr.h3
-rw-r--r--src/array_pthread_t.h1
-rw-r--r--src/array_str.h3
-rw-r--r--src/array_uint.h1
-rw-r--r--src/integral_base.c12
15 files changed, 46 insertions, 10 deletions
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->memory<n){
+ ARRAY_FUNC(resize)(array, n);
+ }
+ for (i=array->length; i<n; i++){
+ ARRAY_VAL_INIT(array->values+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);