Ian Jauslin
summaryrefslogtreecommitdiff
blob: f8761195017c80f79975382fd539dccbd47a35a0 (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
/*
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 double 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_double
// prefix of function names
#define POLYNOMIAL_FUNC(NAME) polynomial_double_ ## NAME

// type of the coefficient
#define POLYNOMIAL_COEF_TYPE double
// type of coefficient arrays
#define POLYNOMIAL_COEFSARRAY_TYPE array_double
// prefix of coefficient array function names
#define POLYNOMIAL_COEFSARRAY_FUNC(NAME) array_double_ ## NAME
// set coefficient
#define POLYNOMIAL_COEF_SET(COEF, VAL) COEF=VAL
// set coefficient from signed int
#define POLYNOMIAL_COEF_SET_SI(COEF, VAL) COEF=(double)VAL
// set coefficient from unsigned int
#define POLYNOMIAL_COEF_SET_UI(COEF, VAL) COEF=(double)VAL
// copy coefficient
#define POLYNOMIAL_COEF_CPY(VAL, COEF) COEF=VAL
// copy coefficient from double
#define POLYNOMIAL_COEF_CPY_D(VAL, COEF) COEF=VAL
// add coefficients
#define POLYNOMIAL_COEF_ADD(COEF, VAL1, VAL2) COEF=VAL1+VAL2
// add coefficients, one of which is specified as a double
#define POLYNOMIAL_COEF_ADD_D(COEF, VAL1, VAL2) COEF=VAL1+VAL2
// multiply coefficients
#define POLYNOMIAL_COEF_MUL(COEF, VAL1, VAL2) COEF=VAL1*VAL2
// multiply coefficients, one of which is specified as a POLYNOMIAL_ORDER_TYPE
#define POLYNOMIAL_COEF_MUL_ORDER(COEF, VAL1, VAL2) COEF=VAL1*(double)VAL2
// divide coefficients, one of which is specified as an unsigned int
#define POLYNOMIAL_COEF_DIV_UI(COEF, VAL1, VAL2) COEF=VAL1/(double)VAL2
// power of a coefficient, specified as an unsigned int
#define POLYNOMIAL_COEF_POW_UI(COEF, VAL1, VAL2) COEF=pow(VAL1, (double)VAL2)
// print a coefficient
#define POLYNOMIAL_COEF_PRINT(COEF) fprint_double(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)