summaryrefslogtreecommitdiff
path: root/atanh.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-01-22 22:30:52 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-01-22 22:30:52 +0000
commit031deac645662aea8a72a5ed0c0bf148e609e681 (patch)
tree07c68b885a0c39a228ca4b0f7f901a9117f85a9f /atanh.c
parent039c1c0135bac8353d17020543fe8b27f3b1937e (diff)
downloadmpfr-031deac645662aea8a72a5ed0c0bf148e609e681.tar.gz
added several hard-coded tests (and fixed bugs found)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2644 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'atanh.c')
-rw-r--r--atanh.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/atanh.c b/atanh.c
index 1062c5b2c..26620a66d 100644
--- a/atanh.c
+++ b/atanh.c
@@ -1,6 +1,6 @@
/* mpfr_atanh -- Inverse Hyperbolic Tangente of Unsigned Integer Number
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -32,24 +32,20 @@ MA 02111-1307, USA. */
int
mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
{
- int inexact =0;
+ int inexact = 0;
mpfr_t x;
- mp_prec_t Nx=MPFR_PREC(xt); /* Precision of input variable */
+ mp_prec_t Nx = MPFR_PREC(xt); /* Precision of input variable */
/* Special cases */
if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(xt) ))
{
- if (MPFR_IS_NAN(xt))
+ /* atanh(NaN) = NaN, and atanh(+/-Inf) = NaN since tanh gives a result
+ between -1 and 1 */
+ if (MPFR_IS_NAN(xt) || MPFR_IS_INF(xt))
{
MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
- else if (MPFR_IS_INF(xt))
- {
- MPFR_SET_INF(y);
- MPFR_SET_SAME_SIGN(y, xt);
- MPFR_RET(0);
- }
else if (MPFR_IS_ZERO(xt))
{
MPFR_SET_ZERO(y); /* atanh(0) = 0 */
@@ -61,9 +57,25 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
}
/* Useless due to final mpfr_set
MPFR_CLEAR_FLAGS(y);*/
-
- mpfr_init2(x,Nx);
- mpfr_abs(x, xt, GMP_RNDN);
+
+ /* atanh(x) = NaN as soon as |x| > 1, and arctanh(+/-1) = +/-Inf */
+ if (MPFR_EXP(xt) > 0)
+ {
+ if (MPFR_EXP(xt) == 1)
+ {
+ if (mpfr_cmp_ui (xt, 1) || mpfr_cmp_si (xt, -1))
+ {
+ MPFR_SET_INF(y);
+ MPFR_SET_SAME_SIGN(y, xt);
+ MPFR_RET(0);
+ }
+ }
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
+ }
+
+ mpfr_init2 (x, Nx);
+ mpfr_abs (x, xt, GMP_RNDN);
/* General case */
{
@@ -108,7 +120,6 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
/* actualisation of the precision */
Nt += 10;
-
}
while ((err < 0) || (!mpfr_can_round (t, err, GMP_RNDN, GMP_RNDZ,
Ny + (rnd_mode == GMP_RNDN))