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

Annotation of OpenXM_contrib/gmp/mpfr/acosh.c, Revision 1.1.1.1

1.1       ohara       1: /* mpfr_acosh -- Inverse Hyperbolic Cosine 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:     acosh= ln(x+sqrt(x-1)*sqrt(x+1))
                     30:  */
                     31:
                     32: int
                     33: mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
                     34: {
                     35:
                     36:   int inexact =0;
                     37:   int comp;
                     38:
                     39:   if (MPFR_IS_NAN(x))
                     40:     {
                     41:       MPFR_SET_NAN(y);
                     42:       MPFR_RET_NAN;
                     43:     }
                     44:
                     45:   comp=mpfr_cmp_ui(x,1);
                     46:
                     47:   if(comp < 0)
                     48:     {
                     49:       MPFR_SET_NAN(y);
                     50:       MPFR_RET_NAN;
                     51:     }
                     52:   MPFR_CLEAR_NAN(y);
                     53:
                     54:   if(comp == 0)
                     55:     {
                     56:       MPFR_SET_ZERO(y); /* acosh(1) = 0 */
                     57:       MPFR_SET_POS(y);
                     58:       MPFR_RET(0);
                     59:     }
                     60:
                     61:   if (MPFR_IS_INF(x))
                     62:     {
                     63:       MPFR_SET_INF(y);
                     64:       MPFR_SET_POS(y);
                     65:       MPFR_RET(0);
                     66:     }
                     67:
                     68:   MPFR_CLEAR_INF(y);
                     69:
                     70:   /* General case */
                     71:   {
                     72:     /* Declaration of the intermediary variable */
                     73:     mpfr_t t, te,ti;
                     74:
                     75:     /* Declaration of the size variable */
                     76:     mp_prec_t Nx = MPFR_PREC(x);   /* Precision of input variable */
                     77:     mp_prec_t Ny = MPFR_PREC(y);   /* Precision of input variable */
                     78:
                     79:     mp_prec_t Nt;   /* Precision of the intermediary variable */
                     80:     int err;  /* Precision of error */
                     81:
                     82:     /* compute the precision of intermediary variable */
                     83:     Nt=MAX(Nx,Ny);
                     84:     /* the optimal number of bits : see algorithms.ps */
                     85:     Nt=Nt+4+_mpfr_ceil_log2(Nt);
                     86:
                     87:     /* initialise of intermediary      variable */
                     88:     mpfr_init(t);
                     89:     mpfr_init(te);
                     90:     mpfr_init(ti);
                     91:
                     92:     /* First computation of cosh */
                     93:     do {
                     94:
                     95:       /* reactualisation of the precision */
                     96:       mpfr_set_prec(t,Nt);
                     97:       mpfr_set_prec(te,Nt);
                     98:       mpfr_set_prec(ti,Nt);
                     99:
                    100:       /* compute acosh */
                    101:       mpfr_mul(te,x,x,GMP_RNDD);  /* (x^2) */
                    102:       mpfr_sub_ui(ti,te,1,GMP_RNDD);  /* (x^2-1) */
                    103:       mpfr_sqrt(t,ti,GMP_RNDN);     /* sqrt(x^2-1) */
                    104:       mpfr_add(t,t,x,GMP_RNDN);    /* sqrt(x^2-1)+x */
                    105:       mpfr_log(t,t,GMP_RNDN);        /* ln(sqrt(x^2-1)+x)*/
                    106:
                    107:       /* estimation of the error see- algorithms.ps*/
                    108:       /*err=Nt-_mpfr_ceil_log2(0.5+pow(2,2-MPFR_EXP(t))+pow(2,1+MPFR_EXP(te)-MPFR_EXP(ti)-MPFR_EXP(t)));*/
                    109:       err=Nt-(-1+2*MAX(2+MAX(2-MPFR_EXP(t),1+MPFR_EXP(te)-MPFR_EXP(ti)-MPFR_EXP(t)),0));
                    110:
                    111:       /* actualisation of the precision */
                    112:       Nt += 10;
                    113:
                    114:     } while ((err<0) ||!mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny));
                    115:
                    116:     inexact = mpfr_set(y,t,rnd_mode);
                    117:
                    118:     mpfr_clear(t);
                    119:     mpfr_clear(ti);
                    120:     mpfr_clear(te);
                    121:   }
                    122:   return inexact;
                    123: }
                    124:
                    125:
                    126:
                    127:
                    128:
                    129:
                    130:
                    131:
                    132:
                    133:
                    134:

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