numerix_doc 0.4
|
00001 00002 /****************************************************************************** 00003 * MODULE : mmx_mpfr.hpp 00004 * DESCRIPTION: Interface to mpfr 00005 * COPYRIGHT : (C) 2003 Joris van der Hoeven 00006 ******************************************************************************* 00007 * This software falls under the GNU general public license and comes WITHOUT 00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00009 * If you don't have this file, write to the Free Software Foundation, Inc., 00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00011 ******************************************************************************/ 00012 00013 #ifndef __MMX_MPFR_HPP 00014 #define __MMX_MPFR_HPP 00015 #include <gmp.h> 00016 #include <mpfr.h> 00017 #include <numerix/mmx_gmp.hpp> 00018 00019 namespace mmx { 00020 00021 /****************************************************************************** 00022 * Global variables 00023 ******************************************************************************/ 00024 00025 extern xnat mmx_significant_digits; // output precision in digits 00026 extern xnat mmx_bit_precision; // working precision in bits 00027 extern xnat mmx_discrepancy; // maximal discrepancy 00028 extern mpfr_rnd_t mmx_rounding_mode; // current rounding mode 00029 extern bool mmx_pretty_exponents; // print 1.0e6 -> 1.0 * 10^6 00030 00031 struct mmx_local_significant_digits { 00032 xnat p; 00033 inline mmx_local_significant_digits (xnat p2): 00034 p (mmx_significant_digits) { 00035 mmx_significant_digits= p2; } 00036 inline ~mmx_local_significant_digits () { 00037 mmx_significant_digits= p; } 00038 }; 00039 00040 struct mmx_local_bit_precision { 00041 xnat p; 00042 inline mmx_local_bit_precision (xnat p2): 00043 p (mmx_bit_precision) { 00044 mmx_bit_precision= p2; } 00045 inline ~mmx_local_bit_precision () { 00046 mmx_bit_precision= p; } 00047 }; 00048 00049 /****************************************************************************** 00050 * Extra routines 00051 ******************************************************************************/ 00052 00053 class string; 00054 extern string mpfr_to_string (const mpz_t x); 00055 extern string mpfr_to_string (const mpfr_t x, xnat bits= 0); 00056 extern string zero_to_string (const mpfr_t err); 00057 00058 inline xnat mpfr_prec_round_up (xnat prec) { 00059 return BITS_PER_LIMB * ((prec + BITS_PER_LIMB - 1) / BITS_PER_LIMB); } 00060 inline mp_exp_t mpfr_get_step (const mpfr_t arg) { 00061 return mpfr_get_exp (arg) - mpfr_get_prec (arg); } 00062 inline mp_exp_t mpfr_safe_get_step (const mpfr_t arg) { 00063 if (mpfr_sgn (arg) == 0) return mpfr_get_emin (); 00064 else return mpfr_get_exp (arg) - mpfr_get_prec (arg); } 00065 inline mp_exp_t mpfr_safe_get_exp (const mpfr_t arg) { 00066 if (mpfr_sgn (arg) == 0) return mpfr_get_emin (); 00067 else return mpfr_get_exp (arg); } 00068 double mpfr_get_magnitude (const mpfr_t arg); 00069 00070 void mpfr_binary_write (const port& p, const mpfr_t arg); 00071 void mpfr_binary_read (const port& p, mpfr_t dest); 00072 00073 } 00074 #endif // __MMX_MPFR_HPP