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

Annotation of OpenXM_contrib/gmp/mpfr/asinh.c, Revision 1.1

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

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