Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/polynomial_mpfr.h')
-rw-r--r--src/polynomial_mpfr.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/polynomial_mpfr.h b/src/polynomial_mpfr.h
new file mode 100644
index 0000000..f8bc983
--- /dev/null
+++ b/src/polynomial_mpfr.h
@@ -0,0 +1,121 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for real polynomials with multi-precision float (mpfr) coefficients and unsigned integer powers
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIAL_TYPENAME
+#undef POLYNOMIAL_FUNC
+#undef POLYNOMIAL_COEF_TYPE
+#undef POLYNOMIAL_COEFSARRAY_TYPE
+#undef POLYNOMIAL_COEFSARRAY_FUNC
+#undef POLYNOMIAL_COEF_INIT
+#undef POLYNOMIAL_COEF_FREE
+#undef POLYNOMIAL_COEF_SET
+#undef POLYNOMIAL_COEF_SET_SI
+#undef POLYNOMIAL_COEF_SET_UI
+#undef POLYNOMIAL_COEF_CPY
+#undef POLYNOMIAL_COEF_CPY_D
+#undef POLYNOMIAL_COEF_ADD
+#undef POLYNOMIAL_COEF_ADD_D
+#undef POLYNOMIAL_COEF_MUL
+#undef POLYNOMIAL_COEF_MUL_ORDER
+#undef POLYNOMIAL_COEF_DIV_UI
+#undef POLYNOMIAL_COEF_POW_UI
+#undef POLYNOMIAL_COEF_PRINT
+#undef POLYNOMIAL_ORDER_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_FUNC
+#undef POLYNOMIAL_ORDER_INIT
+#undef POLYNOMIAL_ORDER_FREE
+#undef POLYNOMIAL_ORDER_SET
+#undef POLYNOMIAL_ORDER_SET_UI
+#undef POLYNOMIAL_ORDER_CPY
+#undef POLYNOMIAL_ORDER_CPY_UI
+#undef POLYNOMIAL_ORDER_ADD
+#undef POLYNOMIAL_ORDER_SUB_UI
+#undef POLYNOMIAL_ORDER_CMP
+#undef POLYNOMIAL_ORDER_CMP_UI
+#undef POLYNOMIAL_ORDER_PRINT
+
+// name of the polynomial type
+#define POLYNOMIAL_TYPENAME polynomial_mpfr
+// prefix of function names
+#define POLYNOMIAL_FUNC(NAME) polynomial_mpfr_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIAL_COEF_TYPE mpfr_t
+// type of coefficient arrays
+#define POLYNOMIAL_COEFSARRAY_TYPE array_mpfr
+// prefix of coefficient array function names
+#define POLYNOMIAL_COEFSARRAY_FUNC(NAME) array_mpfr_ ## NAME
+// init coefficient
+#define POLYNOMIAL_COEF_INIT(VAR) mpfr_init(VAR)
+// free coefficient
+#define POLYNOMIAL_COEF_FREE(VAR) mpfr_clear(VAR)
+// set coefficient
+#define POLYNOMIAL_COEF_SET(COEF, VAL) COEF[0]=VAL[0]
+// set coefficient from signed int
+#define POLYNOMIAL_COEF_SET_SI(COEF, VAL) mpfr_set_si(COEF, VAL, MPFR_RNDN)
+// set coefficient from unsigned int
+#define POLYNOMIAL_COEF_SET_UI(COEF, VAL) mpfr_set_ui(COEF, VAL, MPFR_RNDN)
+// copy coefficient
+#define POLYNOMIAL_COEF_CPY(VAL, COEF) mpfr_init(COEF); mpfr_set(COEF, VAL, MPFR_RNDN)
+// copy coefficient from double
+#define POLYNOMIAL_COEF_CPY_D(VAL, COEF) mpfr_init(COEF); mpfr_set_d(COEF, VAL, MPFR_RNDN)
+// add coefficients
+#define POLYNOMIAL_COEF_ADD(COEF, VAL1, VAL2) mpfr_add(COEF, VAL1, VAL2, MPFR_RNDN)
+// add coefficients, one of which is specified as a double
+#define POLYNOMIAL_COEF_ADD_D(COEF, VAL1, VAL2) mpfr_add_d(COEF, VAL1, VAL2, MPFR_RNDN)
+// multiply coefficients
+#define POLYNOMIAL_COEF_MUL(COEF, VAL1, VAL2) mpfr_mul(COEF, VAL1, VAL2, MPFR_RNDN)
+// multiply coefficients, one of which is specified as a POLYNOMIAL_ORDER_TYPE
+#define POLYNOMIAL_COEF_MUL_ORDER(COEF, VAL1, VAL2) mpfr_mul_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// divide coefficients, one of which is specified as an unsigned int
+#define POLYNOMIAL_COEF_DIV_UI(COEF, VAL1, VAL2) mpfr_div_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// power of a coefficient, specified as an unsigned int
+#define POLYNOMIAL_COEF_POW_UI(COEF, VAL1, VAL2) mpfr_pow_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// print a coefficient
+#define POLYNOMIAL_COEF_PRINT(COEF) fprint_mpfr(stdout, COEF)
+
+// type of the order
+#define POLYNOMIAL_ORDER_TYPE unsigned int
+// type of order arrays
+#define POLYNOMIAL_ORDERSARRAY_TYPE array_uint
+// prefix of order array function names
+#define POLYNOMIAL_ORDERSARRAY_FUNC(NAME) array_uint_ ## NAME
+// set order
+#define POLYNOMIAL_ORDER_SET(ORDER, VAL) ORDER=VAL
+// set order from unsigned int
+#define POLYNOMIAL_ORDER_SET_UI(ORDER, VAL) ORDER=VAL
+// copy order
+#define POLYNOMIAL_ORDER_CPY(VAL, ORDER) ORDER=VAL
+// copy order from unsigned int
+#define POLYNOMIAL_ORDER_CPY_UI(VAL, ORDER) ORDER=VAL
+// add orders
+#define POLYNOMIAL_ORDER_ADD(ORDER, VAL1, VAL2) ORDER=VAL1+VAL2
+// subtract an order and an unsigned integer
+#define POLYNOMIAL_ORDER_SUB_UI(ORDER, VAL1, VAL2) ORDER=VAL1-VAL2
+// compare orders (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP(VAL1, VAL2) (int)VAL1-(int)VAL2
+// compare orders, one of which is specified as an unsigned int (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP_UI(VAL1, VAL2) (int)VAL1-(int)VAL2
+// print orders
+#define POLYNOMIAL_ORDER_PRINT(ORDER) printf("%u",ORDER)
+