/*
This file is part of liberferfc.
Copyright 2009-2010 by
Laboratoire de l'Informatique du Parallélisme, UMR CNRS - ENS Lyon -
UCB Lyon 1 - INRIA 5668,
and by LORIA (CNRS, INPL, INRIA, UHP, U-Nancy 2).
It has been written by S. Chevillard.
Liberferfc is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Liberferfc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with liberferfc. If not, see .
*/
#ifndef H_ERFERFC_UTILS
#define H_ERFERFC_UTILS
#include /* fprintf */
#include /* exit */
#include /* ULONG_MAX */
#include /* mp_exp_t */
#include
#define ASSERT(x) ( (!(x))? (fprintf(stderr, "Assert failed (%s:%d): %s\n", __FILE__, __LINE__, #x), exit(1), 1): 0 )
/* Adds two unsigned int, checking that there is no overflow */
#define ADD_UI_SAFE(x, y) ( ASSERT((x) <= ULONG_MAX - (y)), (x)+(y) )
/* Multiplies two unsigned int, checking that there is no overflow */
#define MUL_UI_SAFE(x, y) ( ASSERT((y) <= ULONG_MAX / (x)), (x)*(y) )
#define SMALL_PRECISION ( (MPFR_PREC_MIN<8*sizeof(unsigned long)) ? \
8*sizeof(unsigned long) : \
MPFR_PREC_MIN )
/* exp(1), rounded to double precision downward and upwards */
#define EINF 2.718281828459045 /* 0x4005bf0a8b145769 */
#define ESUP 2.7182818284590455 /* 0x4005bf0a8b14576a */
/* log2(exp(1)), rounded to double precision upwards */
#define LOG2EINF 1.4426950408889634 /* 0x3ff71547652b82fe */
#define LOG2ESUP 1.4426950408889636 /* 0x3ff71547652b82ff */
/* -log2(e)/e, rounded to double precision upwards */
#define ALPHA -0.5307378454230429 /* 0xbfe0fbcdef1aed58 */
#ifndef mpfr_exp_t
#define mpfr_exp_t mp_exp_t
#endif
#ifndef MPFR_RNDD
#define MPFR_RNDD GMP_RNDD
#endif
#ifndef MPFR_RNDU
#define MPFR_RNDU GMP_RNDU
#endif
#ifndef MPFR_RNDZ
#define MPFR_RNDZ GMP_RNDZ
#endif
#ifndef MPFR_RNDN
#define MPFR_RNDN GMP_RNDN
#endif
int mpfr_my_mul_d(mpfr_t rop, mpfr_t op, double a, mpfr_rnd_t rnd);
int binaryPow(mpfr_t y, mpfr_t x, unsigned long int N, mpfr_rnd_t rnd);
#endif /* H_ERFERFC_UTILS */