1
/* mpfr_sinh -- hyperbolic sine
3
Copyright 2001, 2002 Free Software Foundation, Inc.
5
This file is part of the MPFR Library.
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.
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.
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. */
26
#include "mpfr-impl.h"
28
/* The computation of sinh is done by
30
sinh(x) = 1/2 [e^(x)-e^(-x)]
34
mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode)
36
/****** Declarations ******/
38
mp_prec_t Nxt = MPFR_PREC(xt);
39
int flag_neg=0, inexact =0;
51
MPFR_SET_SAME_SIGN(y, xt);
59
MPFR_SET_ZERO(y); /* sinh(0) = 0 */
60
MPFR_SET_SAME_SIGN(y, xt);
65
mpfr_set (x, xt, GMP_RNDN);
75
/* Declaration of the intermediary variable */
79
/* Declaration of the size variable */
80
mp_prec_t Nx = Nxt; /* Precision of input variable */
81
mp_prec_t Ny = MPFR_PREC(y); /* Precision of input variable */
83
mp_prec_t Nt; /* Precision of the intermediary variable */
84
long int err; /* Precision of error */
86
/* compute the precision of intermediary variable */
88
/* the optimal number of bits : see algorithms.ps */
89
Nt = Nt + _mpfr_ceil_log2 (5) + _mpfr_ceil_log2 (Nt);
91
/* initialise of intermediary variable */
96
/* First computation of sinh */
99
/* reactualisation of the precision */
101
mpfr_set_prec (t, Nt);
102
mpfr_set_prec (te, Nt);
103
mpfr_set_prec (ti, Nt);
106
mpfr_exp (te, x, GMP_RNDD); /* exp(x) */
107
mpfr_ui_div (ti, 1, te, GMP_RNDU); /* 1/exp(x) */
108
mpfr_sub (t, te, ti, GMP_RNDN); /* exp(x) - 1/exp(x) */
109
mpfr_div_2ui (t, t, 1, GMP_RNDN); /* 1/2(exp(x) - 1/exp(x)) */
111
/* it may be that t is zero (in fact, it can only occur when te=1,
112
and thus ti=1 too) */
118
/* calculation of the error */
119
d = MPFR_EXP(te) - MPFR_EXP(t) + 2;
121
/* estimation of the error */
122
/* err = Nt-(_mpfr_ceil_log2(1+pow(2,d)));*/
123
err = Nt - (MAX(d,0) + 1);
126
/* actualisation of the precision */
129
} while ((err < 0) || !mpfr_can_round(t, err, GMP_RNDN, rnd_mode, Ny));
134
inexact = mpfr_set (y, t, rnd_mode);