Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/root_double.h')
-rw-r--r--src/root_double.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/root_double.h b/src/root_double.h
new file mode 100644
index 0000000..f564998
--- /dev/null
+++ b/src/root_double.h
@@ -0,0 +1,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.)
+