summaryrefslogtreecommitdiff
path: root/exp2.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:09:24 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:09:24 +0000
commit026b5b56cd2a5d9adda1aca584842a1da6b0bb44 (patch)
treeebd04ac8ff3e7917ec73790d1b7c958c57c64511 /exp2.c
parent9a885e9800fd6905cebbd85e3d9850f8d356db81 (diff)
downloadmpfr-026b5b56cd2a5d9adda1aca584842a1da6b0bb44.tar.gz
implement ternary inexact flag
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1256 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'exp2.c')
-rw-r--r--exp2.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/exp2.c b/exp2.c
index ddba26174..ae8554bfa 100644
--- a/exp2.c
+++ b/exp2.c
@@ -1,6 +1,6 @@
/* mpfr_exp2 -- power of 2 function 2^y
-Copyright (C) 1999 Free Software Foundation.
+Copyright (C) 1999-2001 Free Software Foundation.
This file is part of the MPFR Library.
@@ -47,20 +47,26 @@ mpfr_exp2 (y, x, rnd_mode)
mpfr_t t;
int round;
- int boucle;
+ int boucle = 1;
+ int inexact = 0;
mp_prec_t Nx; /* Precision of input variable */
mp_prec_t Ny; /* Precision of output variable */
mp_prec_t Nt; /* Precision of Intermediary Calculation variable */
mp_prec_t err; /* Precision of error */
- if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); return 1; }
+ if (MPFR_IS_NAN(x))
+ {
+ MPFR_SET_NAN(y); /* 2^NaN = NaN */
+ return 1;
+ }
MPFR_CLEAR_NAN(y);
- if(mpfr_cmp_ui(x,0)==0){
-
- mpfr_set_ui(y,1,GMP_RNDN);return(0);
- }
+ if (mpfr_cmp_ui (x, 0) == 0)
+ {
+ mpfr_set_ui (y, 1, GMP_RNDN); /* 2^0 = 1 */
+ return 0;
+ }
else
{
@@ -69,23 +75,21 @@ mpfr_exp2 (y, x, rnd_mode)
if (MPFR_SIGN(x) < 0)
{
MPFR_CLEAR_INF(y);
- MPFR_SET_ZERO(y);
- return(0);
+ MPFR_SET_ZERO(y); /* 2^(-Inf) = 0 */
+ return 0;
}
else
{
- MPFR_SET_INF(y);
- if(MPFR_SIGN(y) < 0) MPFR_CHANGE_SIGN(y);
- return(1);
+ MPFR_SET_INF(y); /* 2^(+Inf) = +Inf */
+ if(MPFR_SIGN(y) < 0)
+ MPFR_CHANGE_SIGN(y);
+ return 0;
}
}
}
MPFR_CLEAR_INF(y);
-
-
-
/* Initialisation of the Precision */
Nx=MPFR_PREC(x);
Ny=MPFR_PREC(y);
@@ -97,9 +101,8 @@ mpfr_exp2 (y, x, rnd_mode)
else
Nt=Nx+2*(BITS_PER_CHAR);
- boucle=1;
-
- while(boucle==1){
+ while (boucle)
+ {
/* initialise of intermediary variable */
mpfr_init2(t,Nt);
@@ -111,23 +114,18 @@ mpfr_exp2 (y, x, rnd_mode)
err=Nt-1;
- round=mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny);
+ 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;
- boucle=1;
- }
+ if (round)
+ {
+ inexact = mpfr_set (y, t, rnd_mode);
+ boucle = 0;
+ }
+ else
+ Nt += 10;
}
- mpfr_clear(t);
- return(1);
-
-
-
-
+ mpfr_clear (t);
+ return inexact;
}