diff options
Diffstat (limited to 'src/root_mpfr.h')
-rw-r--r-- | src/root_mpfr.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/root_mpfr.h b/src/root_mpfr.h new file mode 100644 index 0000000..6535e0b --- /dev/null +++ b/src/root_mpfr.h @@ -0,0 +1,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 + |