diff options
Diffstat (limited to 'src/integral_mpfr.h')
-rw-r--r-- | src/integral_mpfr.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/integral_mpfr.h b/src/integral_mpfr.h new file mode 100644 index 0000000..30c9b1a --- /dev/null +++ b/src/integral_mpfr.h @@ -0,0 +1,84 @@ +/* +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 integration using with multi-precision floats (mpfr) +*/ + + +// reset CPP macros +#undef INTEGRAL_FUNC +#undef INTEGRAL_FLOAT_TYPE +#undef INTEGRAL_FLOAT_INIT +#undef INTEGRAL_FLOAT_FREE +#undef INTEGRAL_FLOAT_SET_D +#undef INTEGRAL_FLOAT_SET_UI +#undef INTEGRAL_FLOAT_ADD +#undef INTEGRAL_FLOAT_SUB +#undef INTEGRAL_FLOAT_UI_SUB +#undef INTEGRAL_FLOAT_MUL +#undef INTEGRAL_FLOAT_POW_UI +#undef INTEGRAL_FLOAT_DIV +#undef INTEGRAL_FLOAT_DIV_UI +#undef INTEGRAL_FLOAT_ISNUMBER +#undef INTEGRAL_FLOATARRAY_TYPE +#undef INTEGRAL_FLOATARRAY_FUNC +#undef INTEGRAL_POLYNOMIAL_FUNC +#undef INTEGRAL_POLYNOMIALARRAY_TYPE +#undef INTEGRAL_POLYNOMIALARRAY_FUNC + +// suffix of function names +#define INTEGRAL_FUNC(NAME) NAME ## _mpfr + +// type of floats +#define INTEGRAL_FLOAT_TYPE mpfr_t +// init float +#define INTEGRAL_FLOAT_INIT(VAR) mpfr_init(VAR) +// free float +#define INTEGRAL_FLOAT_FREE(VAR) mpfr_clear(VAR) +// set float from double +#define INTEGRAL_FLOAT_SET_D(FLOAT, VAL) mpfr_set_d(FLOAT, VAL, MPFR_RNDN) +// set float from unsigned int +#define INTEGRAL_FLOAT_SET_UI(FLOAT, VAL) mpfr_set_ui(FLOAT, VAL, MPFR_RNDN) +// add floats +#define INTEGRAL_FLOAT_ADD(FLOAT, VAL1, VAL2) mpfr_add(FLOAT, VAL1, VAL2, MPFR_RNDN) +// subtract floats +#define INTEGRAL_FLOAT_SUB(FLOAT, VAL1, VAL2) mpfr_sub(FLOAT, VAL1, VAL2, MPFR_RNDN) +// subtract floats in which the first is specified as an unsigned int +#define INTEGRAL_FLOAT_UI_SUB(FLOAT, VAL1, VAL2) mpfr_ui_sub(FLOAT, VAL1, VAL2, MPFR_RNDN) +// multiply floats +#define INTEGRAL_FLOAT_MUL(FLOAT, VAL1, VAL2) mpfr_mul(FLOAT, VAL1, VAL2, MPFR_RNDN) +// power of a float, specified as an unsigned int +#define INTEGRAL_FLOAT_POW_UI(FLOAT, VAL1, VAL2) mpfr_pow_ui(FLOAT, VAL1, VAL2, MPFR_RNDN) +// divide floats +#define INTEGRAL_FLOAT_DIV(FLOAT, VAL1, VAL2) mpfr_div(FLOAT, VAL1, VAL2, MPFR_RNDN) +// divide floats, one of which is specified as an unsigned int +#define INTEGRAL_FLOAT_DIV_UI(FLOAT, VAL1, VAL2) mpfr_div_ui(FLOAT, VAL1, VAL2, MPFR_RNDN) +// check whether a float is a regular number +#define INTEGRAL_FLOAT_ISNUMBER(FLOAT) mpfr_number_p(FLOAT)!=0 + +// type of float arrays +#define INTEGRAL_FLOATARRAY_TYPE array_mpfr +// prefix of float array function names +#define INTEGRAL_FLOATARRAY_FUNC(NAME) array_mpfr_ ## NAME + +// prefix of polynomial function names +#define INTEGRAL_POLYNOMIAL_FUNC(NAME) polynomial_mpfr_ ## NAME + +// type of polynomial arrays +#define INTEGRAL_POLYNOMIALARRAY_TYPE array_polynomial_mpfr +// prefix of polynomial array function names +#define INTEGRAL_POLYNOMIALARRAY_FUNC(NAME) array_polynomial_mpfr_ ## NAME |