summaryrefslogtreecommitdiff
path: root/agm.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:01:42 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-15 14:01:42 +0000
commit4ad624ffdfba2d44d9ba542dd08ef1f111753767 (patch)
tree0e2e421b6c9dba1e91b27af0e01c4ce1c48172c8 /agm.c
parentd725f8a09f2be6ed3135f95fdd7290a41e69cff5 (diff)
downloadmpfr-4ad624ffdfba2d44d9ba542dd08ef1f111753767.tar.gz
cosmetic changes
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1248 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'agm.c')
-rw-r--r--agm.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/agm.c b/agm.c
index 1159af31b..04e0a4f5f 100644
--- a/agm.c
+++ b/agm.c
@@ -81,7 +81,7 @@ mpfr_agm (r, op2, op1, rnd_mode)
mp_rnd_t rnd_mode;
#endif
{
- int s, go_on;
+ int s, go_on, compare;
mp_prec_t p, q;
double uo, vo;
mp_limb_t *up, *vp, *tmpp, *tmpup, *tmpvp, *ap, *bp;
@@ -91,25 +91,36 @@ mpfr_agm (r, op2, op1, rnd_mode)
TMP_DECL(marker2);
/* If a or b is NaN, the result is NaN */
- if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2))
- { MPFR_SET_NAN(r); return; }
+ if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2))
+ {
+ MPFR_SET_NAN(r);
+ return;
+ }
/* If a or b is negative (including -Infinity), the result is NaN */
if ((MPFR_SIGN(op1) < 0) || (MPFR_SIGN(op2) < 0))
- { MPFR_SET_NAN(r); return; }
+ {
+ MPFR_SET_NAN(r);
+ return;
+ }
MPFR_CLEAR_NAN(r);
/* If a or b is +Infinity, the result is +Infinity */
if (MPFR_IS_INF(op1) || MPFR_IS_INF(op2))
- { MPFR_SET_INF(r); MPFR_SET_SAME_SIGN(r, op1); return; }
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_SAME_SIGN(r, op1);
+ return;
+ }
MPFR_CLEAR_INF(r);
/* If a or b is 0, the result is 0 */
if ((MPFR_NOTZERO(op1) && MPFR_NOTZERO(op2)) == 0)
- { MPFR_SET_ZERO(r);
- return;
+ {
+ MPFR_SET_ZERO(r);
+ return;
}
/* precision of the following calculus */
@@ -133,12 +144,21 @@ mpfr_agm (r, op2, op1, rnd_mode)
/* b and a will be the 2 operands but I want b>= a */
- if (mpfr_cmp(op1,op2) > 0) {
- mpfr_set(b,op1,GMP_RNDN); mpfr_set(a,op2,GMP_RNDN);
- }
- else {
- mpfr_set(b,op2,GMP_RNDN); mpfr_set(a,op1,GMP_RNDN);
- }
+ if ((compare = mpfr_cmp (op1,op2)) > 0)
+ {
+ mpfr_set (b,op1,GMP_RNDN);
+ mpfr_set (a,op2,GMP_RNDN);
+ }
+ else if (compare == 0)
+ {
+ mpfr_set (r, op1, rnd_mode);
+ return;
+ }
+ else
+ {
+ mpfr_set (b,op2,GMP_RNDN);
+ mpfr_set (a,op1,GMP_RNDN);
+ }
vo=mpfr_get_d(b);
uo=mpfr_get_d(a);
@@ -171,10 +191,10 @@ mpfr_agm (r, op2, op1, rnd_mode)
mpfr_div_2exp(tmpv,tmp,1,GMP_RNDN);
mpfr_set(u,tmpu,GMP_RNDN);
mpfr_set(v,tmpv,GMP_RNDN);
- if (mpfr_cmp(v,u)>=0)
- eq=mpfr_cmp2(v,u);
+ if (mpfr_cmp(v,u) >= 0)
+ eq = mpfr_cmp2(v,u);
else
- eq=mpfr_cmp2(u,v);
+ eq = mpfr_cmp2(u,v);
}
/* printf("avant can_round %i bits faux\n v : ",err+3);