summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:01:18 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:01:18 +0000
commitd725f8a09f2be6ed3135f95fdd7290a41e69cff5 (patch)
tree698606bf80fcdb0dcebc07fcfc74a506fcb17dc3
parent3813ed49eca07ed50b6bfbdcea354da7a1fa6ddf (diff)
downloadmpfr-d725f8a09f2be6ed3135f95fdd7290a41e69cff5.tar.gz
implement ternary inexact flag
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1247 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--sin.c8
-rw-r--r--sinh.c25
-rw-r--r--tan.c8
-rw-r--r--tanh.c49
4 files changed, 39 insertions, 51 deletions
diff --git a/sin.c b/sin.c
index cbe76e2c8..a58e67732 100644
--- a/sin.c
+++ b/sin.c
@@ -35,7 +35,7 @@ mpfr_sin (y, x, rnd_mode)
mp_rnd_t rnd_mode;
#endif
{
- int precy, m, ok, e;
+ int precy, m, ok, e, inexact;
mpfr_t c;
if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
@@ -46,7 +46,7 @@ mpfr_sin (y, x, rnd_mode)
if (!MPFR_NOTZERO(x))
{
- mpfr_set_ui(y, 0, GMP_RNDN);
+ mpfr_set_ui (y, 0, GMP_RNDN);
return 0; /* exact */
}
@@ -77,9 +77,9 @@ mpfr_sin (y, x, rnd_mode)
}
while (!ok);
- mpfr_set (y, c, rnd_mode);
+ inexact = mpfr_set (y, c, rnd_mode);
mpfr_clear (c);
- return 1; /* inexact */
+ return inexact; /* inexact */
}
diff --git a/sinh.c b/sinh.c
index 2578d111f..f43b9c229 100644
--- a/sinh.c
+++ b/sinh.c
@@ -1,6 +1,6 @@
-/* mpfr_sinh -- Hyperbolic Sinus of Unsigned Integer Number
+/* mpfr_sinh -- hyperbolic sine
-Copyright (C) 1999 Free Software Foundation.
+Copyright (C) 2001 Free Software Foundation.
This file is part of the MPFR Library.
@@ -51,7 +51,7 @@ mpfr_sinh (y, x, rnd_mode)
mpfr_t te,ti;
int round;
- int boucle;
+ int boucle = 1, inexact = 0;
mp_prec_t Nx; /* Precision of input variable */
mp_prec_t Ny; /* Precision of output variable */
@@ -72,16 +72,15 @@ mpfr_sinh (y, x, rnd_mode)
else{
if (MPFR_SIGN(y) > 0) MPFR_CHANGE_SIGN(y);
}
- return 1;
+ return 0;
}
MPFR_CLEAR_INF(y);
if(!MPFR_NOTZERO(x)){
MPFR_SET_ZERO(y); /* sinh(0) = 0 */
if (MPFR_SIGN(y) < 0) MPFR_CHANGE_SIGN(y);
- return(0);
+ return 0;
}
- else{
/* Initialisation of the Precision */
Nx=MPFR_PREC(x);
@@ -93,14 +92,13 @@ mpfr_sinh (y, x, rnd_mode)
else
Nt=Nx+2*(BITS_PER_CHAR);
- boucle=1;
-
/* initialise of intermediary variable */
mpfr_init2(t,Nt);
mpfr_init2(te,Nt);
mpfr_init2(ti,Nt);
- while(boucle==1){
+ while (boucle)
+ {
/* compute sinh */
mpfr_exp(te,x,GMP_RNDN); /* exp(x) */
@@ -113,7 +111,7 @@ mpfr_sinh (y, x, rnd_mode)
round=mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny);
if(round == 1){
- mpfr_set(y,t,rnd_mode);
+ inexact = mpfr_set (y, t, rnd_mode);
boucle=0;
}
else{
@@ -122,8 +120,6 @@ mpfr_sinh (y, x, rnd_mode)
mpfr_set_prec(t,Nt);
mpfr_set_prec(te,Nt);
mpfr_set_prec(ti,Nt);
-
- boucle=1;
}
}
@@ -132,8 +128,5 @@ mpfr_sinh (y, x, rnd_mode)
mpfr_clear(ti);
mpfr_clear(te);
- return(1);
-
-
- }
+ return inexact;
}
diff --git a/tan.c b/tan.c
index 2f0bc5559..580cc5924 100644
--- a/tan.c
+++ b/tan.c
@@ -36,7 +36,7 @@ mpfr_tan (y, x, rnd_mode)
mp_rnd_t rnd_mode;
#endif
{
- int precy, m, ok, e;
+ int precy, m, ok, e, inexact;
mpfr_t c;
if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
@@ -47,7 +47,7 @@ mpfr_tan (y, x, rnd_mode)
if (!MPFR_NOTZERO(x))
{
- mpfr_set_ui(y, 0, GMP_RNDN);
+ mpfr_set_ui (y, 0, GMP_RNDN);
return 0; /* exact */
}
@@ -81,9 +81,9 @@ mpfr_tan (y, x, rnd_mode)
}
while (!ok);
- mpfr_set (y, c, rnd_mode);
+ inexact = mpfr_set (y, c, rnd_mode);
mpfr_clear (c);
- return 1; /* inexact */
+ return inexact;
}
diff --git a/tanh.c b/tanh.c
index 41ec91b81..0f7730f6f 100644
--- a/tanh.c
+++ b/tanh.c
@@ -1,6 +1,6 @@
-/* mpfr_tanh -- Hyperbolic Tangent of Unsigned Integer Number
+/* mpfr_tanh -- hyperbolic tangent
-Copyright (C) 1999 Free Software Foundation.
+Copyright (C) 2001 Free Software Foundation.
This file is part of the MPFR Library.
@@ -51,7 +51,7 @@ mpfr_tanh (y, x, rnd_mode)
mpfr_t te,ta,tb;
int round;
- int boucle;
+ int boucle = 1, inexact = 0;
mp_prec_t Nx; /* Precision of input variable */
mp_prec_t Ny; /* Precision of output variable */
@@ -69,17 +69,15 @@ mpfr_tanh (y, x, rnd_mode)
else
mpfr_set_si(y,-1,GMP_RNDN); /* tanh(inf) = -1 */
- return(0);
+ return 0;
}
if(!MPFR_NOTZERO(x)){ /* tanh(0) = 0 */
MPFR_CLEAR_INF(y);
MPFR_SET_ZERO(y);
if (MPFR_SIGN(y) < 0) MPFR_CHANGE_SIGN(y);
- return(0);
+ return 0;
}
- else{
-
/* Initialisation of the Precision */
Nx=MPFR_PREC(x);
@@ -99,9 +97,8 @@ mpfr_tanh (y, x, rnd_mode)
mpfr_init2(ta,Nt);
mpfr_init2(tb,Nt);
- while(boucle==1){
-
-
+ while (boucle)
+ {
/* compute tanh */
mpfr_mul_2exp(te,x,1,GMP_RNDN); /* 2x */
mpfr_exp(te,te,GMP_RNDN); /* exp(2x) */
@@ -113,28 +110,26 @@ mpfr_tanh (y, x, rnd_mode)
round=mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny);
- if(round == 1){
- mpfr_set(y,t,rnd_mode);
- boucle=0;
- }
- else{
- Nt=Nt+10;
+ if(round)
+ {
+ inexact = mpfr_set (y, t, rnd_mode);
+ boucle=0;
+ }
+ else
+ {
+ Nt=Nt+10;
/* re-initialise of intermediary variable */
- mpfr_set_prec(t,Nt);
- mpfr_set_prec(te,Nt);
- mpfr_set_prec(ta,Nt);
- mpfr_set_prec(tb,Nt);
- boucle=1;
- }
+ mpfr_set_prec(t,Nt);
+ mpfr_set_prec(te,Nt);
+ mpfr_set_prec(ta,Nt);
+ mpfr_set_prec(tb,Nt);
+ }
- }
+ }
mpfr_clear(t);
mpfr_clear(te);
mpfr_clear(ta);
mpfr_clear(tb);
- return(1);
-
-
- }
+ return inexact;
}