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

Annotation of OpenXM_contrib/gmp/mpfr/mpfr-impl.h, Revision 1.1.1.2

1.1       maekawa     1: /* Utilities for MPFR developers, not exported.
                      2:
1.1.1.2 ! ohara       3: Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
1.1       maekawa     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
1.1.1.2 ! ohara       8: it under the terms of the GNU Lesser General Public License as published by
        !             9: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1       maekawa    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
1.1.1.2 ! ohara      14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    15: License for more details.
                     16:
1.1.1.2 ! ohara      17: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    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:
1.1.1.2 ! ohara      22: /* Test if X (positive) is a power of 2 */
1.1       maekawa    23:
1.1.1.2 ! ohara      24: #define IS_POW2(X) (((X) & ((X) - 1)) == 0)
        !            25: #define NOT_POW2(X) (((X) & ((X) - 1)) != 0)
1.1       maekawa    26:
1.1.1.2 ! ohara      27: /* This unsigned type must correspond to the signed one defined in gmp.h */
        !            28: #if defined (_CRAY) && ! defined (_CRAYMPP)
        !            29: typedef unsigned int            mp_exp_unsigned_t;
        !            30: typedef unsigned int            mp_size_unsigned_t;
        !            31: #else
        !            32: typedef unsigned long int       mp_exp_unsigned_t;
        !            33: typedef unsigned long int       mp_size_unsigned_t;
        !            34: #endif
        !            35:
        !            36: #define MP_EXP_T_MAX ((mp_exp_t) ((~ (mp_exp_unsigned_t) 0) >> 1))
        !            37: #define MP_EXP_T_MIN (-MP_EXP_T_MAX-1)
        !            38:
        !            39: #define MP_LIMB_T_ONE ((mp_limb_t) 1)
        !            40:
        !            41: #if (BITS_PER_MP_LIMB & (BITS_PER_MP_LIMB - 1))
        !            42: #error "BITS_PER_MP_LIMB must be a power of 2"
        !            43: #endif
        !            44:
        !            45: #define MPFR_INTPREC_MAX (ULONG_MAX & ~(unsigned long) (BITS_PER_MP_LIMB - 1))
        !            46:
        !            47: /* Assertions */
        !            48:
        !            49: /* Compile with -DWANT_ASSERT to check all assert statements */
        !            50:
        !            51: /* MPFR_ASSERTN(expr): assertions that should always be checked */
        !            52: /* #define MPFR_ASSERTN(expr) ASSERT_ALWAYS(expr) */
        !            53: #define MPFR_ASSERTN(expr)  ((expr) ? (void) 0 : (void) ASSERT_FAIL (expr))
        !            54:
        !            55: /* MPFR_ASSERTD(expr): assertions that should be checked when testing */
        !            56: /* #define MPFR_ASSERTD(expr) ASSERT(expr) */
        !            57: #if WANT_ASSERT
        !            58: #define MPFR_ASSERTD(expr)  ASSERT_ALWAYS (expr)
        !            59: #else
        !            60: #define MPFR_ASSERTD(expr)  ((void) 0)
        !            61: #endif
        !            62:
        !            63: /* Definition of constants */
        !            64:
        !            65: #define LOG2 0.69314718055994528622 /* log(2) rounded to zero on 53 bits */
        !            66: #define ALPHA 4.3191365662914471407 /* a+2 = a*log(a), rounded to +infinity */
        !            67:
        !            68: /* Safe absolute value (to avoid possible integer overflow) */
        !            69:
        !            70: #define SAFE_ABS(type,x) ((x) >= 0 ? (unsigned type)(x) : -(unsigned type)(x))
        !            71:
        !            72: /* macros for doubles, based on gmp union ieee_double_extract */
        !            73:
        !            74: typedef union ieee_double_extract Ieee_double_extract;
        !            75:
        !            76: #define DOUBLE_ISNANorINF(x) (((Ieee_double_extract *)&(x))->s.exp == 0x7ff)
        !            77: #define DOUBLE_ISINF(x) (DOUBLE_ISNANorINF(x) && \
        !            78:                         (((Ieee_double_extract *)&(x))->s.manl == 0) && \
        !            79:                          (((Ieee_double_extract *)&(x))->s.manh == 0))
        !            80: #define DOUBLE_ISNAN(x) (DOUBLE_ISNANorINF(x) && \
        !            81:                         ((((Ieee_double_extract *)&(x))->s.manl != 0) || \
        !            82:                          (((Ieee_double_extract *)&(x))->s.manh != 0)))
        !            83:
        !            84: #define DBL_POS_INF (1.0/0.0)
        !            85: #define DBL_NEG_INF (-1.0/0.0)
        !            86: #define DBL_NAN (0.0/0.0)
        !            87:
        !            88: /* bit 31 of _mpfr_size is used for sign,
        !            89:    bit 30 of _mpfr_size is used for Nan flag,
        !            90:    bit 29 of _mpfr_size is used for Inf flag,
        !            91:    remaining bits are used to store the number of allocated limbs */
        !            92: #define MPFR_CLEAR_FLAGS(x) \
        !            93:   (((x) -> _mpfr_size &= ~((mp_size_unsigned_t) 3 << 29)))
        !            94: #define MPFR_IS_NAN(x) (((x)->_mpfr_size >> 30) & 1)
        !            95: #define MPFR_SET_NAN(x) ((x)->_mpfr_size |= ((mp_size_unsigned_t) 1 << 30))
        !            96: #define MPFR_CLEAR_NAN(x) \
        !            97:   (((x) -> _mpfr_size &= ~((mp_size_unsigned_t) 1 << 30)))
        !            98: #define MPFR_IS_INF(x) (((x)->_mpfr_size >> 29) & 1)
        !            99: #define MPFR_SET_INF(x) ((x)->_mpfr_size |= ((mp_size_unsigned_t) 1 << 29))
        !           100: #define MPFR_CLEAR_INF(x) ((x)->_mpfr_size &= ~((mp_size_unsigned_t) 1 << 29))
        !           101: #define MPFR_IS_FP(x) ((((x) -> _mpfr_size >> 29) & 3) == 0)
        !           102: #define MPFR_ABSSIZE(x) \
        !           103:   ((x)->_mpfr_size & (((mp_size_unsigned_t) 1 << 29) - 1))
        !           104: #define MPFR_SET_ABSSIZE(x, n) \
        !           105:   ((x)->_mpfr_size = ((x)->_mpfr_size & ((mp_size_unsigned_t) 7 << 29)) \
        !           106:                      | (mp_size_unsigned_t) (n))
        !           107: #define MPFR_SIZE(x) ((x)->_mpfr_size)
        !           108: #define MPFR_EXP(x) ((x)->_mpfr_exp)
        !           109: #define MPFR_MANT(x) ((x)->_mpfr_d)
        !           110: #define MPFR_ISNONNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) >= 0)
        !           111: #define MPFR_ISNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x) == -1)
        !           112: #define MPFR_SET_POS(x) (MPFR_SIZE(x) &= ~(((mp_size_unsigned_t) 1) << 31))
        !           113: #define MPFR_SET_NEG(x) (MPFR_SIZE(x) |= (((mp_size_unsigned_t) 1) << 31))
        !           114: #define MPFR_CHANGE_SIGN(x) (MPFR_SIZE(x) ^= (((mp_size_unsigned_t) 1) << 31))
        !           115: #define MPFR_SET_SAME_SIGN(x, y) \
        !           116:   (MPFR_SIGN((x)) != MPFR_SIGN((y)) && (MPFR_CHANGE_SIGN((x)), 0))
        !           117: #define MPFR_PREC(x) ((x)->_mpfr_prec)
        !           118: #define MPFR_NOTZERO(x) \
        !           119:   (MPFR_MANT(x)[(MPFR_PREC(x)-1)/BITS_PER_MP_LIMB] != (mp_limb_t) 0)
        !           120: #define MPFR_IS_ZERO(x) \
        !           121:   (MPFR_MANT(x)[(MPFR_PREC(x)-1)/BITS_PER_MP_LIMB] == (mp_limb_t) 0)
        !           122: #define MPFR_SET_ZERO(x) \
        !           123:   (MPFR_MANT(x)[(MPFR_PREC(x)-1)/BITS_PER_MP_LIMB] = (mp_limb_t) 0)
        !           124: #define MPFR_ESIZE(x) \
        !           125:   ((MPFR_PREC((x)) - 1) / BITS_PER_MP_LIMB + 1);
        !           126: #define MPFR_EVEN_INEX 2
        !           127:
        !           128: /* When returning the ternary inexact value, ALWAYS use one of the
        !           129:    following two macros, unless the flag comes from another function
        !           130:    returning the ternary inexact value */
        !           131: #define MPFR_RET(I) return \
        !           132:   (I) ? ((__mpfr_flags |= MPFR_FLAGS_INEXACT), (I)) : 0
        !           133: #define MPFR_RET_NAN return (__mpfr_flags |= MPFR_FLAGS_NAN), 0
        !           134:
        !           135: /* The following macro restores the exponent range and the flags,
        !           136:    checks that the result is in the exponent range and returns the
        !           137:    ternary inexact value. */
        !           138: #define MPFR_RESTORE_RET(inex, x, rnd_mode) \
        !           139:   do \
        !           140:     { \
        !           141:       int inex_cr; \
        !           142:       mpfr_restore_emin_emax(); \
        !           143:       inex_cr = mpfr_check_range(x, rnd_mode); \
        !           144:       if (inex_cr) \
        !           145:         return inex_cr; /* underflow or overflow */ \
        !           146:       MPFR_RET(inex); \
        !           147:     } \
        !           148:   while(0)
        !           149:
        !           150: /* Memory gestion */
        !           151:
        !           152: /* temporary allocate s limbs at xp, and initialize mpfr variable x */
        !           153: #define MPFR_INIT(xp, x, p, s) \
        !           154:   (xp = (mp_ptr) TMP_ALLOC((size_t) (s) * BYTES_PER_MP_LIMB), \
        !           155:    MPFR_PREC(x) = (p), \
        !           156:    MPFR_MANT(x) = (xp), \
        !           157:    MPFR_SIZE(x) = (s), \
        !           158:    MPFR_EXP(x) = 0)
        !           159: /* same when xp is already allocated */
        !           160: #define MPFR_INIT1(xp, x, p, s) \
        !           161:   (MPFR_PREC(x) = (p), MPFR_MANT(x) = (xp), MPFR_SIZE(x) = (s))
        !           162:
        !           163: #ifndef _PROTO
        !           164: #if defined (__STDC__) || defined (__cplusplus)
        !           165: #define _PROTO(x) x
        !           166: #else
        !           167: #define _PROTO(x) ()
        !           168: #endif
        !           169: #endif
        !           170:
        !           171: #if defined (__cplusplus)
        !           172: extern "C" {
        !           173: #endif
        !           174:
        !           175: extern mp_prec_t __mpfr_const_log2_prec;
        !           176: int mpfr_set_underflow _PROTO ((mpfr_ptr, mp_rnd_t, int));
        !           177: int mpfr_set_overflow _PROTO ((mpfr_ptr, mp_rnd_t, int));
        !           178: void mpfr_save_emin_emax _PROTO ((void));
        !           179: void mpfr_restore_emin_emax _PROTO ((void));
        !           180: int mpfr_add1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
        !           181:                        mp_rnd_t, mp_exp_unsigned_t));
        !           182: int mpfr_sub1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
        !           183:                        mp_rnd_t, int));
        !           184: int mpfr_round_raw_generic _PROTO ((mp_limb_t *, mp_limb_t *, mp_prec_t, int,
        !           185:                                    mp_prec_t, mp_rnd_t, int *, int));
        !           186: int mpfr_can_round_raw _PROTO ((mp_limb_t *, mp_size_t, int, mp_exp_t,
        !           187:                                mp_rnd_t, mp_rnd_t, mp_prec_t));
        !           188: double mpfr_get_d3 _PROTO ((mpfr_srcptr, mp_exp_t, mp_rnd_t));
        !           189: int mpfr_cmp_abs _PROTO ((mpfr_srcptr, mpfr_srcptr));
        !           190: int mpfr_cmp2 _PROTO ((mpfr_srcptr, mpfr_srcptr, mp_prec_t *));
        !           191: long _mpfr_ceil_log2 _PROTO ((double));
        !           192: long _mpfr_floor_log2 _PROTO ((double));
        !           193: double _mpfr_ceil_exp2 _PROTO ((double));
        !           194: unsigned long _mpfr_isqrt _PROTO ((unsigned long));
        !           195: unsigned long _mpfr_cuberoot _PROTO ((unsigned long));
        !           196: int mpfr_exp_2 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
        !           197: int mpfr_exp3 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
        !           198:
        !           199: #define mpfr_round_raw(yp, xp, xprec, neg, yprec, r, inexp) \
        !           200:   mpfr_round_raw_generic((yp), (xp), (xprec), (neg), (yprec), (r), (inexp), 0)
        !           201:
        !           202: #define mpfr_round_raw2(xp, xn, neg, r, prec) \
        !           203:   mpfr_round_raw_generic(0, (xp), (xn) * BITS_PER_MP_LIMB, (neg), \
        !           204:                         (prec), (r), 0, 1);
1.1       maekawa   205:
1.1.1.2 ! ohara     206: #if defined (__cplusplus)
1.1       maekawa   207: }
1.1.1.2 ! ohara     208: #endif

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