Annotation of OpenXM_contrib/gmp/mpfr/atanh.c, Revision 1.1
1.1 ! ohara 1: /* mpfr_atanh -- Inverse Hyperbolic Tangente of Unsigned Integer Number
! 2:
! 3: Copyright 2001, 2002 Free Software Foundation.
! 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 Lesser General Public License as published by
! 9: the Free Software Foundation; either version 2.1 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 Lesser General Public
! 15: License for more details.
! 16:
! 17: You should have received a copy of the GNU Lesser 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 "gmp.h"
! 23: #include "gmp-impl.h"
! 24: #include "mpfr.h"
! 25: #include "mpfr-impl.h"
! 26:
! 27: /* The computation of acosh is done by
! 28:
! 29: atanh= 1/2*ln(x+1)-1/2*ln(1-x)
! 30: */
! 31:
! 32: int
! 33: mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
! 34: {
! 35: int inexact =0;
! 36: mpfr_t x;
! 37: int flag_neg=0;
! 38:
! 39: mp_prec_t Nx=MPFR_PREC(xt); /* Precision of input variable */
! 40: mpfr_init2(x,Nx);
! 41: mpfr_set(x,xt,GMP_RNDN);
! 42:
! 43: if (MPFR_SIGN(x) < 0)
! 44: {
! 45: MPFR_CHANGE_SIGN(x);
! 46: flag_neg=1;
! 47: }
! 48:
! 49: if (MPFR_IS_NAN(x))
! 50: {
! 51: MPFR_SET_NAN(y);
! 52: mpfr_clear(x);
! 53: MPFR_RET_NAN;
! 54: }
! 55: MPFR_CLEAR_NAN(y);
! 56:
! 57:
! 58: if (MPFR_IS_INF(x))
! 59: {
! 60: MPFR_SET_INF(y);
! 61: MPFR_SET_SAME_SIGN(y,x);
! 62: if(flag_neg)
! 63: MPFR_CHANGE_SIGN(y);
! 64: mpfr_clear(x);
! 65: MPFR_RET(0);
! 66: }
! 67:
! 68: MPFR_CLEAR_INF(y);
! 69:
! 70: if (MPFR_IS_ZERO(x))
! 71: {
! 72: MPFR_SET_ZERO(y); /* atanh(0) = 0 */
! 73: MPFR_SET_SAME_SIGN(y,x);
! 74: if(flag_neg)
! 75: MPFR_CHANGE_SIGN(y);
! 76: mpfr_clear(x);
! 77: MPFR_RET(0);
! 78: }
! 79:
! 80: /* General case */
! 81: {
! 82: /* Declaration of the intermediary variable */
! 83: mpfr_t t, te,ti;
! 84:
! 85: /* Declaration of the size variable */
! 86: mp_prec_t Nx = MPFR_PREC(x); /* Precision of input variable */
! 87: mp_prec_t Ny = MPFR_PREC(y); /* Precision of input variable */
! 88:
! 89: mp_prec_t Nt; /* Precision of the intermediary variable */
! 90: long int err; /* Precision of error */
! 91:
! 92: /* compute the precision of intermediary variable */
! 93: Nt=MAX(Nx,Ny);
! 94: /* the optimal number of bits : see algorithms.ps */
! 95: Nt=Nt+4+_mpfr_ceil_log2(Nt);
! 96:
! 97: /* initialise of intermediary variable */
! 98: mpfr_init(t);
! 99: mpfr_init(te);
! 100: mpfr_init(ti);
! 101:
! 102: /* First computation of cosh */
! 103: do {
! 104:
! 105: /* reactualisation of the precision */
! 106: mpfr_set_prec(t,Nt);
! 107: mpfr_set_prec(te,Nt);
! 108: mpfr_set_prec(ti,Nt);
! 109:
! 110: /* compute atanh */
! 111: mpfr_ui_sub(te,1,x,GMP_RNDU); /* (1-xt)*/
! 112: mpfr_add_ui(ti,x,1,GMP_RNDD); /* (xt+1)*/
! 113: mpfr_div(te,ti,te,GMP_RNDN); /* (1+xt)/(1-xt)*/
! 114: mpfr_log(te,te,GMP_RNDN); /* ln((1+xt)/(1-xt))*/
! 115: mpfr_div_2ui(t,te,1,GMP_RNDN); /* (1/2)*ln((1+xt)/(1-xt))*/
! 116:
! 117: /* estimation of the error see- algorithms.ps*/
! 118: /* err=Nt-_mpfr_ceil_log2(1+5*pow(2,1-MPFR_EXP(t)));*/
! 119: err=Nt-(MAX(4-MPFR_EXP(t),0)+1);
! 120:
! 121: /* actualisation of the precision */
! 122: Nt += 10;
! 123:
! 124: } while ((err < 0) || (!mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny) || (MPFR_IS_ZERO(t))));
! 125:
! 126: if(flag_neg)
! 127: MPFR_CHANGE_SIGN(t);
! 128:
! 129: inexact = mpfr_set(y,t,rnd_mode);
! 130:
! 131: mpfr_clear(t);
! 132: mpfr_clear(ti);
! 133: mpfr_clear(te);
! 134: }
! 135: mpfr_clear(x);
! 136: return inexact;
! 137: }
! 138:
! 139:
! 140:
! 141:
! 142:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>