[BACK]Return to mpfr.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpfr

Annotation of OpenXM_contrib/gmp/mpfr/mpfr.h, Revision 1.1.1.1

1.1       maekawa     1: /* mpfr.h -- Include file for mpfr.
                      2:
                      3: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
                      4:
                      5: This file is part of the MPFR Library.
                      6:
                      7: The MPFR Library is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU Library General Public License as published by
                      9: the Free Software Foundation; either version 2 of the License, or (at your
                     10: option) any later version.
                     11:
                     12: The MPFR Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
                     15: License for more details.
                     16:
                     17: You should have received a copy of the GNU Library General Public License
                     18: along with the MPFR Library; see the file COPYING.LIB.  If not, write to
                     19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
                     22: #include <stdio.h>
                     23:
                     24: /* Cygnus does not know about *rand48 functions */
                     25: #ifdef __CYGWIN32__
                     26: #define mrand48 rand
                     27: #define drand48 rand
                     28: #define lrand48 rand
                     29: #define srand48 srand
                     30: #endif
                     31:
                     32: /* Definition of rounding modes */
                     33:
                     34: #define GMP_RNDN 0
                     35: #define GMP_RNDZ 1
                     36: #define GMP_RNDU 2
                     37: #define GMP_RNDD 3
                     38:
                     39: /* Definitions of types and their semantics */
                     40:
                     41: typedef struct {
                     42:   unsigned long int _mp_prec; /* WARNING : for the mpfr type, the precision */
                     43:                               /* should be understood as the number of BITS,*/
                     44:                              /* not the number of mp_limb_t's. This means  */
                     45:                              /* that the corresponding number of allocated
                     46:                                 limbs is >= ceil(_mp_prec/BITS_PER_MP_LIMB) */
                     47:   mp_size_t _mp_size;         /* abs(_mp_size) is the number of allocated
                     48:                                 limbs the field _mp_d points to.
                     49:                                 The sign is that of _mp_size.
                     50:                                 The number 0 is such that _mp_d[k-1]=0
                     51:                                 where k = ceil(_mp_prec/BITS_PER_MP_LIMB) */
                     52:   mp_exp_t _mp_exp;
                     53:   mp_limb_t *_mp_d;
                     54: }
                     55: __mpfr_struct;
                     56:
                     57: /*
                     58:    The number represented is
                     59:
                     60:     sign(_mp_size)*(_mp_d[k-1]/B+_mp_d[k-2]/B^2+...+_mp_d[0]/B^k)*2^_mp_exp
                     61:
                     62:    where k=ceil(_mp_prec/BITS_PER_MP_LIMB) and B=2^BITS_PER_MP_LIMB.
                     63:
                     64:    For the msb (most significant bit) normalized representation, we must have
                     65:    _mp_d[k-1]>=B/2, unless the number is zero (in that case its sign is still
                     66:    given by sign(_mp_size)).
                     67:
                     68:    We must also have the last k*BITS_PER_MP_LIMB-_mp_prec bits set to zero.
                     69: */
                     70:
                     71: typedef __mpfr_struct mpfr_t[1];
                     72: typedef __mpfr_struct *mpfr_ptr;
                     73: typedef __gmp_const __mpfr_struct *mpfr_srcptr;
                     74:
                     75:
                     76: /* Prototypes */
                     77:
                     78: #ifndef _PROTO
                     79: #if defined (__STDC__) || defined (__cplusplus)
                     80: #define _PROTO(x) x
                     81: #else
                     82: #define _PROTO(x) ()
                     83: #endif
                     84: #endif
                     85:
                     86: /* bit 31 of _mp_size is used for sign,
                     87:    bit 30 of _mp_size is used for Nan flag,
                     88:    remaining bits are used to store the number of allocated limbs */
                     89: #define FLAG_NAN(x) (((x)->_mp_size >> 30)&1)
                     90: #define SET_NAN(x) ((x)->_mp_size |= (1<<30))
                     91: #define ABSSIZE(x) ((x)->_mp_size & ((1<<30)-1))
                     92: #define SIZE(x) ((x)->_mp_size)
                     93: #define EXP(x) ((x)->_mp_exp)
                     94: #define MANT(x) ((x)->_mp_d)
                     95: #define SIGN(x) (((x)->_mp_size >> 31) ? -1 : 1)
                     96: #define ISNONNEG(x) (SIGN(x)>=0)
                     97: #define ISNEG(x) (SIGN(x)==-1)
                     98: #define CHANGE_SIGN(x) (SIZE(x) = SIZE(x) ^ (1<<31))
                     99: #define PREC(x) ((x)->_mp_prec)
                    100: #define NOTZERO(x) (MANT(x)[(PREC(x)-1)/BITS_PER_MP_LIMB])
                    101: #define SET_ZERO(x) (MANT(x)[(PREC(x)-1)/BITS_PER_MP_LIMB] = 0)
                    102:
                    103: /* reallocates the mantissa of x to q bits and sets the precision to q */
                    104: #define _mpfr_realloc(x, q) { \
                    105:     (x)->_mp_d = (mp_ptr) (*_mp_reallocate_func) \
                    106:        ((x)->_mp_d, (x)->_mp_prec>>3 + 1, (q)>>3 + 1); \
                    107:     (x)->_mp_prec = q; }
                    108:
                    109: void mpfr_init2 _PROTO ((mpfr_ptr, unsigned long int));
                    110: int mpfr_round_raw _PROTO ((mp_limb_t *, mp_limb_t *, unsigned long, char,
                    111:                             unsigned long, char));
                    112: int mpfr_round_raw2 _PROTO ((mp_limb_t *, unsigned long, char, char,
                    113:                             unsigned long));
                    114: void mpfr_round _PROTO ((mpfr_ptr, char, unsigned long));
                    115: int mpfr_can_round _PROTO ((mpfr_ptr, unsigned long, unsigned char,
                    116:                            unsigned char, unsigned long));
                    117: int mpfr_can_round_raw _PROTO ((mp_limb_t *, unsigned long, int,
                    118:                                unsigned long,
                    119:                                unsigned char, unsigned char, unsigned long));
                    120: void mpfr_set_d _PROTO ((mpfr_ptr, double, unsigned char));
                    121: int mpfr_set_z _PROTO ((mpfr_ptr, mpz_srcptr, unsigned char));
                    122: double mpfr_get_d _PROTO ((mpfr_srcptr));
                    123: double mpfr_get_d2 _PROTO ((mpfr_srcptr, long));
                    124: void mpfr_set_f _PROTO ((mpfr_ptr, mpf_srcptr, char));
                    125: void mpfr_set_si _PROTO ((mpfr_ptr, long, unsigned char));
                    126: void mpfr_set_ui _PROTO ((mpfr_ptr, unsigned long, unsigned char));
                    127: void mpfr_print_raw _PROTO ((mpfr_srcptr));
                    128: void mpfr_random _PROTO ((mpfr_ptr));
                    129: void mpfr_clear _PROTO ((mpfr_ptr));
                    130: void mpfr_set_str_raw _PROTO ((mpfr_ptr, char *));
                    131: void mpfr_get_str_raw _PROTO ((char *, mpfr_srcptr));
                    132: char* mpfr_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpfr_srcptr, unsigned char));
                    133: size_t mpfr_out_str _PROTO ((FILE *, int, size_t, mpfr_srcptr, unsigned char));
                    134: void mpfr_mul _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char));
                    135: void mpfr_pow_ui _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned int, unsigned char));
                    136: void mpfr_ui_pow_ui _PROTO ((mpfr_ptr, unsigned int, unsigned int, unsigned char));
                    137: mp_limb_t mpn_divrem_n _PROTO ((mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t));
                    138: mp_size_t kara_sqrtrem _PROTO ((mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t));
                    139: void mpfr_div _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char));
                    140: void mpfr_agm _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char));
                    141: int mpfr_sqrt _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char));
                    142: void mpfr_add _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char));
                    143: int mpfr_add_one_ulp _PROTO ((mpfr_ptr));
                    144: void mpfr_sub _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char));
                    145: void mpfr_set4 _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char, int));
                    146: void mpfr_pi _PROTO ((mpfr_ptr, unsigned char));
                    147: void mpfr_log2 _PROTO ((mpfr_ptr, unsigned char));
                    148: int mpfr_log _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char));
                    149: int mpfr_exp _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char));
                    150: int mpfr_zeta _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char));
                    151: void mpfr_mul_ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long, unsigned char));
                    152: void mpfr_set_machine_rnd_mode _PROTO ((unsigned char));
                    153: int mpfr_cmp3 _PROTO ((mpfr_srcptr, mpfr_srcptr, long int));
                    154: int mpfr_cmp_ui_2exp _PROTO ((mpfr_srcptr, unsigned long int, int));
                    155: int mpfr_cmp_si_2exp _PROTO ((mpfr_srcptr, long int, int));
                    156: int mpfr_cmp2 _PROTO ((mpfr_srcptr, mpfr_srcptr));
                    157: void mpfr_mul_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int,unsigned char));
                    158: void mpfr_div_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int,unsigned char));
                    159: void mpfr_set_prec _PROTO((mpfr_ptr, unsigned long int));
                    160: void mpfr_set_default_prec _PROTO((unsigned long int));
                    161: extern mp_size_t __gmp_default_fp_bit_precision;
                    162: extern char __gmp_default_rounding_mode;
                    163: char * mpfr_print_rnd_mode _PROTO((unsigned char));
                    164: void mpfr_neg _PROTO((mpfr_ptr, mpfr_srcptr, unsigned char));
                    165: int mpfr_sub_one_ulp _PROTO((mpfr_ptr x));
                    166: int mpfr_div_ui _PROTO((mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char rnd_mode));
                    167: unsigned long int mpfr_get_prec _PROTO((mpfr_t x));
                    168:
                    169: #define mpfr_init(x) mpfr_init2(x, __gmp_default_fp_bit_precision)
                    170: #define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp(b,i,0)
                    171: #define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp(b,i,0)
                    172: #define mpfr_set(a,b,r) mpfr_set4(a,b,r,SIGN(b))
                    173: #define mpfr_cmp(b,c) mpfr_cmp3(b,c,1)
                    174:
                    175: #if (BITS_PER_MP_LIMB==32)
                    176: #define MPFR_LIMBS_PER_DOUBLE 2
                    177: #elif (BITS_PER_MP_LIMB==64)
                    178: #define MPFR_LIMBS_PER_DOUBLE 1
                    179: #endif
                    180:
                    181: /* gmp-2.0.2 had only one threshold for both multiplication and squaring */
                    182: #ifndef KARATSUBA_MUL_THRESHOLD
                    183: #ifdef KARATSUBA_THRESHOLD
                    184: #define KARATSUBA_MUL_THRESHOLD KARATSUBA_THRESHOLD
                    185: #else
                    186: #define KARATSUBA_MUL_THRESHOLD 16
                    187: #endif
                    188: #endif
                    189:
                    190: #define mpfr_init_set_si(x, i, p, rnd) \
                    191:  mpfr_init2((x), (p)); mpfr_set_si((x), (i), (rnd));
                    192: #define mpfr_init_set_ui(x, i, p, rnd) \
                    193:  mpfr_init2((x), (p)); mpfr_set_ui((x), (i), (rnd));
                    194: #define mpfr_init_set_d(x, d, p, rnd) \
                    195:  mpfr_init2((x), (p)); mpfr_set_d((x), (d), (rnd));
                    196: #define mpfr_init_set(x, y, p, rnd) \
                    197:  mpfr_init2((x), (p)); mpfr_set((x), (y), (rnd));
                    198: #define mpfr_init_set_f(x, y, p, rnd) \
                    199:  mpfr_init2((x), (p)); mpfr_set_f((x), (y), (rnd));
                    200: #define mpfr_init_set_str(x, y, p, rnd) \
                    201:  mpfr_init2((x), (p)); mpfr_set_str((x), (y), (rnd));
                    202: #define mpfr_init_set_str_raw(x, y, p, rnd) \
                    203:  mpfr_init2((x), (p)); mpfr_set_str_raw((x), (y), (rnd));
                    204:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>