blob: f5649986a31b9acb4308ee58fd71fa6e65c9fae7 (
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
|
/*
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 doubles
*/
// 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 ## _double
// type of floats
#define ROOT_FLOAT_TYPE double
// set float
#define ROOT_FLOAT_SET(FLOAT, VAL) FLOAT=VAL
// subtract floats
#define ROOT_FLOAT_SUB(FLOAT, VAL1, VAL2) FLOAT=VAL1-VAL2
// divide floats
#define ROOT_FLOAT_DIV(FLOAT, VAL1, VAL2) FLOAT=VAL1/VAL2
// compare floats (0 if equal, -1 if <, +1 if >)
#define ROOT_FLOAT_CMP(VAL1, VAL2) VAL1-VAL2
// abs of float
#define ROOT_FLOAT_ABS(FLOAT, VAL) FLOAT=fabs(VAL)
// check whether a float is a regular number
#define ROOT_FLOAT_ISNUMBER(FLOAT) (fpclassify(FLOAT)>=FP_ZERO)
// whether float is 0
#define ROOT_FLOAT_ISZERO(VAL) (VAL==0.)
|