Ian Jauslin
summaryrefslogtreecommitdiff
blob: f8bc983b952a624c79f2f7dbb2e230449cb8241d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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)