Ian Jauslin
summaryrefslogtreecommitdiff
blob: 6535e0b29582bd65137a091b8eb5522cf06779e6 (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
/*
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 root finding using multi-precision floats (mpfr)
*/


// reset CPP macros
#undef ROOT_FUNC
#undef ROOT_FLOAT_TYPE
#undef ROOT_FLOAT_INIT
#undef ROOT_FLOAT_FREE
#undef ROOT_FLOAT_SET
#undef ROOT_FLOAT_SUB
#undef ROOT_FLOAT_DIV
#undef ROOT_FLOAT_CMP
#undef ROOT_FLOAT_ABS
#undef ROOT_FLOAT_ISNUMBER
#undef ROOT_FLOAT_ISZERO


// suffix of function names
#define ROOT_FUNC(NAME) NAME ## _mpfr

// type of floats
#define ROOT_FLOAT_TYPE mpfr_t
// init float
#define ROOT_FLOAT_INIT(VAR) mpfr_init(VAR)
// free float
#define ROOT_FLOAT_FREE(VAR) mpfr_clear(VAR)
// set float
#define ROOT_FLOAT_SET(FLOAT, VAL) mpfr_set(FLOAT, VAL, MPFR_RNDN)
// subtract floats
#define ROOT_FLOAT_SUB(FLOAT, VAL1, VAL2) mpfr_sub(FLOAT, VAL1, VAL2, MPFR_RNDN)
// divide floats
#define ROOT_FLOAT_DIV(FLOAT, VAL1, VAL2) mpfr_div(FLOAT, VAL1, VAL2, MPFR_RNDN)
// compare floats (0 if equal, -1 if <, +1 if >)
#define ROOT_FLOAT_CMP(VAL1, VAL2) mpfr_cmp(VAL1, VAL2)
// abs of float
#define ROOT_FLOAT_ABS(FLOAT, VAL) mpfr_abs(FLOAT, VAL, MPFR_RNDN)
// check whether a float is a regular number
#define ROOT_FLOAT_ISNUMBER(FLOAT) mpfr_number_p(FLOAT)!=0
// whether float is 0
#define ROOT_FLOAT_ISZERO(VAL) mpfr_zero_p(VAL)!=0