Annotation of OpenXM_contrib/gmp/mpfr/expm1.c, Revision 1.1.1.1
1.1 ohara 1: /* mpfr_expm1 -- Compute exp(x)-1
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 expm1 is done by
28:
29: expm1(x)=exp(x)-1
30: */
31:
32: int
33: mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
34: {
35: int inexact = 0;
36:
37: if (MPFR_IS_NAN(x))
38: {
39: MPFR_SET_NAN(y);
40: MPFR_RET_NAN;
41: }
42:
43: MPFR_CLEAR_NAN(y);
44:
45: /* check for inf or -inf (expm1(-inf)=-1) */
46: if (MPFR_IS_INF(x))
47: {
48: if (MPFR_SIGN(x) > 0)
49: {
50: MPFR_SET_INF(y);
51: MPFR_SET_POS(y);
52: return 0;
53: }
54: else
55: return mpfr_set_si(y, -1, rnd_mode);
56: }
57:
58: MPFR_CLEAR_INF(y);
59:
60: if(MPFR_IS_ZERO(x))
61: {
62: MPFR_SET_ZERO(y); /* expm1(+/- 0) = +/- 0 */
63: MPFR_SET_SAME_SIGN(y,x);
64: MPFR_RET(0);
65: }
66:
67: /* General case */
68: {
69: /* Declaration of the intermediary variable */
70: mpfr_t te,t;
71:
72: /* Declaration of the size variable */
73: mp_prec_t Nx = MPFR_PREC(x); /* Precision of input variable */
74: mp_prec_t Ny = MPFR_PREC(y); /* Precision of input variable */
75:
76: mp_prec_t Nt; /* Precision of the intermediary variable */
77: long int err; /* Precision of error */
78:
79: /* compute the precision of intermediary variable */
80: Nt=MAX(Nx,Ny);
81: /* the optimal number of bits : see algorithms.ps */
82: Nt=Nt+5+_mpfr_ceil_log2(Nt);
83:
84: /* initialise of intermediary variable */
85: mpfr_init(t);
86: mpfr_init(te);
87:
88: /* First computation of cosh */
89: do {
90:
91: /* reactualisation of the precision */
92: mpfr_set_prec(t,Nt);
93: mpfr_set_prec(te,Nt);
94:
95: /* compute expm1 */
96: mpfr_exp(te,x,GMP_RNDN); /* exp(x)*/
97: mpfr_sub_ui(t,te,1,GMP_RNDN); /* exp(x)-1 */
98:
99: /* estimation of the error */
100: /*err=Nt-(_mpfr_ceil_log2(1+pow(2,MPFR_EXP(te)-MPFR_EXP(t))));*/
101: err=Nt-(MAX(MPFR_EXP(te)-MPFR_EXP(t),0)+1);
102:
103: /* actualisation of the precision */
104: Nt += 10;
105:
106: } while ((err <0) || !mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny));
107:
108: inexact = mpfr_set(y,t,rnd_mode);
109:
110: mpfr_clear(t);
111: mpfr_clear(te);
112: }
113: return inexact;
114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>