summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-02-01 21:35:34 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-02-01 21:35:34 +0000
commit6e879c6f3361346ede165d0733a26e9145cccf69 (patch)
treeba27f0eb5a934b1be7da19ed5937cb8f7b076608
parentd2a8d03f413280358567c13baa9b2e1f6e3349bf (diff)
downloadmpfr-6e879c6f3361346ede165d0733a26e9145cccf69.tar.gz
Misc bug fixes and code clean-up.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1678 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--acosh.c4
-rw-r--r--agm.c4
-rw-r--r--asinh.c54
-rw-r--r--atanh.c10
-rw-r--r--copysign.c48
-rw-r--r--cos.c6
-rw-r--r--cosh.c17
-rw-r--r--dim.c29
-rw-r--r--div_ui.c22
-rw-r--r--exp.c24
-rw-r--r--exp2.c27
-rw-r--r--expm1.c24
-rw-r--r--hypot.c29
-rw-r--r--log.c29
-rw-r--r--log10.c64
-rw-r--r--log1p.c43
-rw-r--r--log2.c65
-rw-r--r--pow_si.c78
18 files changed, 230 insertions, 347 deletions
diff --git a/acosh.c b/acosh.c
index 6953b9b37..6e626eca6 100644
--- a/acosh.c
+++ b/acosh.c
@@ -1,6 +1,6 @@
/* mpfr_acosh -- Inverse Hyperbolic Cosine of Unsigned Integer Number
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -39,7 +39,7 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
comp=mpfr_cmp_ui(x,1);
diff --git a/agm.c b/agm.c
index 7f8a35213..c19298f3d 100644
--- a/agm.c
+++ b/agm.c
@@ -1,6 +1,6 @@
/* mpfr_agm -- arithmetic-geometric mean of two floating-point numbers
-Copyright (C) 1999, 2001 Free Software Foundation.
+Copyright (C) 1999-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -86,6 +86,7 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2))
{
MPFR_SET_NAN(r);
+ __mpfr_flags |= MPFR_FLAGS_NAN;
return;
}
@@ -93,6 +94,7 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode)
if ((MPFR_SIGN(op1) < 0) || (MPFR_SIGN(op2) < 0))
{
MPFR_SET_NAN(r);
+ __mpfr_flags |= MPFR_FLAGS_NAN;
return;
}
diff --git a/asinh.c b/asinh.c
index a4ab317af..ac6de2595 100644
--- a/asinh.c
+++ b/asinh.c
@@ -1,6 +1,6 @@
/* mpfr_asinh -- Inverse Hyperbolic Sinus of Unsigned Integer Number
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -29,51 +29,45 @@ MA 02111-1307, USA. */
asinh= ln(x+sqrt(x^2+1))
*/
int
-mpfr_asinh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
+mpfr_asinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode)
{
- int inexact =0;
+ int inexact;
mpfr_t x;
int flag_neg=0;
+ mp_prec_t Nx;
- mp_prec_t Nx=MPFR_PREC(xt); /* Precision of input variable */
- mpfr_init2(x,Nx);
- mpfr_set(x,xt,GMP_RNDN);
-
- if (MPFR_SIGN(x) < 0)
- {
- MPFR_CHANGE_SIGN(x);
- flag_neg=1;
- }
-
- if (MPFR_IS_NAN(x))
+ if (MPFR_IS_NAN(xt))
{
MPFR_SET_NAN(y);
- mpfr_clear(x);
- return 1;
+ MPFR_RET_NAN;
}
+
MPFR_CLEAR_NAN(y);
-
- if (MPFR_IS_INF(x))
+ if (MPFR_IS_INF(xt))
{
MPFR_SET_INF(y);
- MPFR_SET_SAME_SIGN(y,x);
- if(flag_neg)
- MPFR_CHANGE_SIGN(y);
- mpfr_clear(x);
- return 1;
+ MPFR_SET_SAME_SIGN(y, xt);
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
- if(!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(xt))
{
MPFR_SET_ZERO(y); /* asinh(0) = 0 */
- MPFR_SET_SAME_SIGN(y,x);
- if(flag_neg)
- MPFR_CHANGE_SIGN(y);
- mpfr_clear(x);
- return 0;
+ MPFR_SET_SAME_SIGN(y, xt);
+ MPFR_RET(0);
+ }
+
+ Nx = MPFR_PREC(xt); /* Precision of input variable */
+ mpfr_init2(x, Nx);
+ mpfr_set(x, xt, GMP_RNDN);
+
+ if (MPFR_SIGN(x) < 0)
+ {
+ MPFR_CHANGE_SIGN(x);
+ flag_neg=1;
}
/* General case */
@@ -132,5 +126,5 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
mpfr_clear(te);
}
mpfr_clear(x);
- return inexact;
+ MPFR_RET(inexact);
}
diff --git a/atanh.c b/atanh.c
index b59f72659..fd175ca37 100644
--- a/atanh.c
+++ b/atanh.c
@@ -1,6 +1,6 @@
/* mpfr_atanh -- Inverse Hyperbolic Tangente of Unsigned Integer Number
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -50,7 +50,7 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
{
MPFR_SET_NAN(y);
mpfr_clear(x);
- return 1;
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
@@ -62,19 +62,19 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
if(flag_neg)
MPFR_CHANGE_SIGN(y);
mpfr_clear(x);
- return 0;
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
- if(!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(x))
{
MPFR_SET_ZERO(y); /* atanh(0) = 0 */
MPFR_SET_SAME_SIGN(y,x);
if(flag_neg)
MPFR_CHANGE_SIGN(y);
mpfr_clear(x);
- return 0;
+ MPFR_RET(0);
}
/* General case */
diff --git a/copysign.c b/copysign.c
index 1dd88dc2f..6a15ec0ce 100644
--- a/copysign.c
+++ b/copysign.c
@@ -1,6 +1,6 @@
/* mpfr_copysign -- Produce a value with the magnitude of x and sign of y
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -19,7 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "mpfr.h"
@@ -31,46 +30,13 @@ MA 02111-1307, USA. */
*/
int
-mpfr_copysign (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode)
+mpfr_copysign (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode)
{
-
- if (MPFR_IS_NAN(y))
- {
- MPFR_SET_NAN(z);
- return 1;
- }
-
- if (MPFR_IS_NAN(x))
- {
- MPFR_SET_NAN(z);
- MPFR_SET_SAME_SIGN(z,y);
- return 1;
- }
-
- MPFR_CLEAR_NAN(z);
-
- if (MPFR_IS_INF(x)) {
-
- MPFR_SET_INF(z);
- MPFR_SET_SAME_SIGN(z,y);
- return 0;
- }
-
- MPFR_CLEAR_INF(z);
-
- if (!MPFR_NOTZERO(x))
- {
- MPFR_SET_ZERO(z);
- MPFR_SET_SAME_SIGN(z,y);
- return 0;
- }
-
- /* GENERAL CASE*/
+ if (MPFR_IS_NAN(y))
{
- int inexact=0;
- inexact =mpfr_set(z,x,rnd_mode);
- MPFR_SET_SAME_SIGN(z,y);
- return inexact;
+ MPFR_SET_NAN(z);
+ MPFR_RET_NAN;
}
-
+ else
+ return mpfr_set4(z, x, rnd_mode, MPFR_SIGN(y));
}
diff --git a/cos.c b/cos.c
index a2346b614..197c19e6c 100644
--- a/cos.c
+++ b/cos.c
@@ -1,6 +1,6 @@
/* mpfr_cos -- cosine of a floating-point number
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -36,10 +36,10 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
- if (!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(x))
{
mpfr_set_ui (y, 1, GMP_RNDN);
return 0;
diff --git a/cosh.c b/cosh.c
index 98b0ede6e..458615398 100644
--- a/cosh.c
+++ b/cosh.c
@@ -1,6 +1,6 @@
/* mpfr_cosh -- hyperbolic cosine
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -42,7 +42,7 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(xt))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
@@ -51,21 +51,16 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
MPFR_SET_INF(y);
if (MPFR_SIGN(y) < 0)
MPFR_CHANGE_SIGN(y);
- return 0;
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
- if(!MPFR_NOTZERO(xt))
- return mpfr_set_ui(y,1,rnd_mode); /* cosh(0) = 1 */
+ if (MPFR_IS_ZERO(xt))
+ return mpfr_set_ui(y,1,rnd_mode); /* cosh(0) = 1 */
mpfr_init2(x,Nxt);
- mpfr_set(x,xt,GMP_RNDN);
-
- if(MPFR_SIGN(x)<0)
- {
- MPFR_CHANGE_SIGN(x);
- }
+ mpfr_set4(x, xt, GMP_RNDN, 1);
/* General case */
{
diff --git a/dim.c b/dim.c
index 4715ba95d..39e981c8d 100644
--- a/dim.c
+++ b/dim.c
@@ -1,6 +1,6 @@
/* mpfr_dim -- dim of x, y
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -19,7 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "mpfr.h"
@@ -32,24 +31,22 @@ MA 02111-1307, USA. */
*/
int
-mpfr_dim (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode)
+mpfr_dim (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode)
{
-
- if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y) )
- {
- MPFR_SET_NAN(z);
- return 1;
+ if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y))
+ {
+ MPFR_SET_NAN(z);
+ MPFR_RET_NAN;
}
- MPFR_CLEAR_NAN(z);
- if(mpfr_cmp(x,y) > 0)
- return mpfr_sub(z,x,y,rnd_mode);
- else
+ MPFR_CLEAR_NAN(z);
+
+ if (mpfr_cmp(x,y) > 0)
+ return mpfr_sub(z, x, y, rnd_mode);
+ else
{
MPFR_SET_ZERO(z);
- if(MPFR_SIGN(z) < 0)
- MPFR_CHANGE_SIGN(z);
- return 0;
+ MPFR_SET_POS(z);
+ MPFR_RET(0);
}
}
-
diff --git a/div_ui.c b/div_ui.c
index db4aa0c63..69a44007f 100644
--- a/div_ui.c
+++ b/div_ui.c
@@ -1,6 +1,6 @@
/* mpfr_div_ui -- divide a floating-point number by a machine integer
-Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+Copyright (C) 1999-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -45,13 +45,12 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
if (MPFR_IS_INF(x))
{
- MPFR_SET_INF(y);
- if (MPFR_SIGN(y) * MPFR_SIGN(x) < 0) /* consider u=0 as +0 */
- MPFR_CHANGE_SIGN(y);
- return 0;
+ MPFR_SET_INF(y);
+ MPFR_SET_SAME_SIGN(y, x);
+ MPFR_RET(0);
}
- if (u == 0)
+ if (u == 0)
{
if (MPFR_IS_ZERO(x)) /* 0/0 is NaN */
{
@@ -59,19 +58,20 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
MPFR_RET_NAN;
}
else /* x/0 is Inf */
- {
+ {
MPFR_SET_INF(y);
MPFR_SET_SAME_SIGN(y, x);
- return 0;
+ MPFR_RET(0);
}
}
MPFR_CLEAR_INF(y);
-
+ MPFR_SET_SAME_SIGN(y, x);
+
if (MPFR_IS_ZERO(x))
{
MPFR_SET_ZERO(y);
- return 0;
+ MPFR_RET(0);
}
TMP_MARK(marker);
@@ -81,8 +81,6 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
xp = MPFR_MANT(x);
yp = MPFR_MANT(y);
MPFR_EXP(y) = MPFR_EXP(x);
- if (MPFR_SIGN(x) * MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
dif = yn + 1 - xn;
diff --git a/exp.c b/exp.c
index 089975e6f..185320886 100644
--- a/exp.c
+++ b/exp.c
@@ -1,6 +1,6 @@
/* mpfr_exp -- exponential of a floating-point number
-Copyright (C) 1999-2001 Free Software Foundation.
+Copyright (C) 1999-2002 Free Software Foundation.
Contributed by the Spaces project.
This file is part of the MPFR Library.
@@ -44,36 +44,30 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
- if (MPFR_IS_INF(x))
- {
+ if (MPFR_IS_INF(x))
+ {
if (MPFR_SIGN(x) > 0)
{
MPFR_SET_INF(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
}
else
{
MPFR_CLEAR_INF(y);
MPFR_SET_ZERO(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
}
- return 0;
+ MPFR_SET_POS(y);
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
-
- if (!MPFR_NOTZERO(x))
- {
- mpfr_set_ui (y, 1, GMP_RNDN);
- return 0;
- }
+
+ if (MPFR_IS_ZERO(x))
+ return mpfr_set_ui (y, 1, GMP_RNDN);
expx = MPFR_EXP(x);
precy = MPFR_PREC(y);
diff --git a/exp2.c b/exp2.c
index 3768778f5..8370510a1 100644
--- a/exp2.c
+++ b/exp2.c
@@ -1,6 +1,6 @@
/* mpfr_exp2 -- power of 2 function 2^y
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -37,35 +37,30 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(x))
{
- MPFR_SET_NAN(y);
- return 1;
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
if (MPFR_IS_INF(x))
{
- if (MPFR_SIGN(x) < 0)
+ if (MPFR_SIGN(x) > 0)
{
- MPFR_SET_ZERO(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 0;
+ MPFR_SET_INF(y);
}
else
{
- MPFR_SET_INF(y);
- if(MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 0;
+ MPFR_CLEAR_INF(y);
+ MPFR_SET_ZERO(y);
}
+ MPFR_SET_POS(y);
+ MPFR_RET(0);
}
/* 2^0 = 1 */
- if(mpfr_cmp_ui(x,0)==0)
- {
- return mpfr_set_ui(y,1,rnd_mode);
- }
+ if (MPFR_IS_ZERO(x))
+ return mpfr_set_ui (y, 1, rnd_mode);
/* General case */
{
diff --git a/expm1.c b/expm1.c
index cdb41072d..c3cca2b54 100644
--- a/expm1.c
+++ b/expm1.c
@@ -1,6 +1,6 @@
/* mpfr_expm1 -- Compute exp(x)-1
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -32,38 +32,36 @@ MA 02111-1307, USA. */
int
mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
{
-
int inexact = 0;
- if (MPFR_IS_NAN(x))
+ if (MPFR_IS_NAN(x))
{
- MPFR_SET_NAN(y);
- return 1;
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
}
- MPFR_CLEAR_NAN(y);
+ MPFR_CLEAR_NAN(y);
/* check for inf or -inf (expm1(-inf)=-1) */
if (MPFR_IS_INF(x))
{
- if(MPFR_SIGN(x) > 0)
+ if (MPFR_SIGN(x) > 0)
{
MPFR_SET_INF(y);
- MPFR_SET_SAME_SIGN(y,x);
+ MPFR_SET_POS(y);
return 0;
}
- else
- return mpfr_set_ui(y,-1,rnd_mode);
+ else
+ return mpfr_set_si(y, -1, rnd_mode);
}
MPFR_CLEAR_INF(y);
-
- if(!MPFR_NOTZERO(x))
+ if(MPFR_IS_ZERO(x))
{
MPFR_SET_ZERO(y); /* expm1(+/- 0) = +/- 0 */
MPFR_SET_SAME_SIGN(y,x);
- return 0;
+ MPFR_RET(0);
}
/* General case */
diff --git a/hypot.c b/hypot.c
index 1e799f9a9..6ee55942e 100644
--- a/hypot.c
+++ b/hypot.c
@@ -1,6 +1,6 @@
/* mpfr_hypot -- Euclidean distance
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -41,27 +41,26 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode)
/* particular cases */
if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y))
- {
- MPFR_SET_NAN(z);
- return 1;
- }
+ {
+ MPFR_SET_NAN(z);
+ MPFR_RET_NAN;
+ }
MPFR_CLEAR_NAN(z);
if (MPFR_IS_INF(x) || MPFR_IS_INF(y))
- {
- MPFR_SET_INF(z);
- if (MPFR_SIGN(z) < 0)
- MPFR_CHANGE_SIGN(z);
- return 0;
- }
+ {
+ MPFR_SET_INF(z);
+ MPFR_SET_POS(z);
+ MPFR_RET(0);
+ }
MPFR_CLEAR_INF(z);
-
- if(!MPFR_NOTZERO(x))
+
+ if(MPFR_IS_ZERO(x))
return mpfr_abs (z, y, rnd_mode);
-
- if(!MPFR_NOTZERO(y))
+
+ if(MPFR_IS_ZERO(y))
return mpfr_abs (z, x, rnd_mode);
/* General case */
diff --git a/log.c b/log.c
index 64adb0884..97b1607af 100644
--- a/log.c
+++ b/log.c
@@ -1,6 +1,6 @@
/* mpfr_log -- natural logarithm of a floating-point number
-Copyright (C) 1999, 2001 Free Software Foundation.
+Copyright (C) 1999-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -55,7 +55,7 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(a))
{
MPFR_SET_NAN(r);
- return 1; /* NaN is inexact */
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(r);
@@ -66,40 +66,39 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
if (MPFR_SIGN(a) < 0) /* log(-Inf) = NaN */
{
MPFR_SET_NAN(r);
- return 1;
+ MPFR_RET_NAN;
}
else /* log(+Inf) = +Inf */
{
MPFR_SET_INF(r);
- if (MPFR_SIGN(r) < 0)
- MPFR_CHANGE_SIGN(r);
- return 0;
+ MPFR_SET_POS(r);
+ MPFR_RET(0);
}
}
/* Now we can clear the flags without damage even if r == a */
- MPFR_CLEAR_INF(r);
+ MPFR_CLEAR_INF(r);
- if (MPFR_IS_ZERO(a))
+ if (MPFR_IS_ZERO(a))
{
- MPFR_SET_INF(r);
- if (MPFR_SIGN(r) > 0)
- MPFR_CHANGE_SIGN(r);
- return 0; /* log(0) is an exact infinity */
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* log(0) is an exact infinity */
}
/* If a is negative, the result is NaN */
if (MPFR_SIGN(a) < 0)
{
MPFR_SET_NAN(r);
- return 1;
+ MPFR_RET_NAN;
}
/* If a is 1, the result is 0 */
- if (mpfr_cmp_ui_2exp (a, 1, 0) == 0)
+ if (mpfr_cmp_ui (a, 1) == 0)
{
MPFR_SET_ZERO(r);
- return 0; /* only "normal" case where the result is exact */
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* only "normal" case where the result is exact */
}
q=MPFR_PREC(r);
diff --git a/log10.c b/log10.c
index b1e5e7d6f..b9e7a3ff7 100644
--- a/log10.c
+++ b/log10.c
@@ -1,6 +1,6 @@
/* mpfr_log10 -- log in base 10
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -31,9 +31,8 @@ MA 02111-1307, USA. */
*/
int
-mpfr_log10 (mpfr_ptr r, mpfr_srcptr a , mp_rnd_t rnd_mode)
+mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
{
-
int inexact = 0;
/* If a is NaN, the result is NaN */
@@ -43,58 +42,49 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a , mp_rnd_t rnd_mode)
MPFR_RET_NAN;
}
- /* If a is negative, the result is NaN */
- if (MPFR_SIGN(a) < 0)
- {
- if (!MPFR_IS_INF(a) && MPFR_IS_ZERO(a))
- {
- MPFR_CLEAR_NAN(r);
- MPFR_SET_INF(r);
- if (MPFR_SIGN(r) > 0)
- MPFR_CHANGE_SIGN(r);
- return 0;
- }
- else
- {
- MPFR_SET_NAN(r);
- MPFR_RET_NAN;
- }
- }
-
MPFR_CLEAR_NAN(r);
/* check for infinity before zero */
if (MPFR_IS_INF(a))
{
- /* only +Inf can go here */
- MPFR_SET_INF(r);
- if(MPFR_SIGN(r) < 0)
- MPFR_CHANGE_SIGN(r);
- return 0;
+ if (MPFR_SIGN(a) < 0) /* log10(-Inf) = NaN */
+ {
+ MPFR_SET_NAN(r);
+ MPFR_RET_NAN;
+ }
+ else /* log10(+Inf) = +Inf */
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0);
+ }
}
/* Now we can clear the flags without damage even if r == a */
+ MPFR_CLEAR_INF(r);
- MPFR_CLEAR_INF(r);
+ if (MPFR_IS_ZERO(a))
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* log10(0) is an exact infinity */
+ }
- if (MPFR_IS_ZERO(a))
+ /* If a is negative, the result is NaN */
+ if (MPFR_SIGN(a) < 0)
{
- MPFR_SET_INF(r);
- if (MPFR_SIGN(r) > 0)
- MPFR_CHANGE_SIGN(r);
- /* Execption GMP*/
- return 0;
+ MPFR_SET_NAN(r);
+ MPFR_RET_NAN;
}
/* If a is 1, the result is 0 */
- if (mpfr_cmp_ui(a,1) == 0)
+ if (mpfr_cmp_ui(a, 1) == 0)
{
- MPFR_SET_SAME_SIGN(r,a);
MPFR_SET_ZERO(r);
- return 0;
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* only "normal" case where the result is exact */
}
-
/* General case */
{
/* Declaration of the intermediary variable */
diff --git a/log1p.c b/log1p.c
index 3eb4d110e..ae3e410a5 100644
--- a/log1p.c
+++ b/log1p.c
@@ -1,6 +1,6 @@
/* mpfr_log1p -- Compute log(1+x)
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -30,63 +30,58 @@ MA 02111-1307, USA. */
*/
int
-mpfr_log1p (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode)
+mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
int comp, inexact = 0;
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
+
MPFR_CLEAR_NAN(y);
/* check for inf or -inf (result is not defined) */
if (MPFR_IS_INF(x))
- {
- if(MPFR_SIGN(x) > 0)
+ {
+ if (MPFR_SIGN(x) > 0)
{
MPFR_SET_INF(y);
-
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
-
- return 0;
+ MPFR_SET_POS(y);
+ MPFR_RET(0);
}
else
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
}
comp = mpfr_cmp_si(x,-1);
/* x<-1 undefined */
- if(comp < 0)
- {
- MPFR_SET_NAN(y);
- return 1;
+ if (comp < 0)
+ {
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
}
/* x=0: log1p(-1)=-inf (division by zero) */
- if(comp == 0)
+ if (comp == 0)
{
- DIVIDE_BY_ZERO; /* Exception GMP */
- MPFR_SET_INF(y);
- if (MPFR_SIGN(y) > 0)
- MPFR_CHANGE_SIGN(y);
- return 1;
+ MPFR_SET_INF(y);
+ MPFR_SET_POS(y);
+ MPFR_RET_NAN;
}
MPFR_CLEAR_INF(y);
- if(!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(x))
{
MPFR_SET_ZERO(y); /* log1p(+/- 0) = +/- 0 */
MPFR_SET_SAME_SIGN(y, x);
- return 0;
+ MPFR_RET(0);
}
-
/* General case */
{
/* Declaration of the intermediary variable */
diff --git a/log2.c b/log2.c
index 234249e16..80db9911e 100644
--- a/log2.c
+++ b/log2.c
@@ -1,6 +1,6 @@
/* mpfr_log2 -- log base 2
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -31,9 +31,8 @@ MA 02111-1307, USA. */
*/
int
-mpfr_log2 (mpfr_ptr r, mpfr_srcptr a , mp_rnd_t rnd_mode)
+mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
{
-
int inexact = 0;
/* If a is NaN, the result is NaN */
@@ -45,53 +44,45 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a , mp_rnd_t rnd_mode)
MPFR_CLEAR_NAN(r);
- /* If a is negative, the result is NaN */
- if (MPFR_SIGN(a) < 0)
- {
- if (!MPFR_IS_INF(a) && MPFR_IS_ZERO(a))
- {
- MPFR_SET_INF(r);
- if (MPFR_SIGN(r) > 0)
- MPFR_CHANGE_SIGN(r);
- return 0;
- }
- else
- {
- MPFR_SET_NAN(r);
- MPFR_RET_NAN;
- }
- }
-
/* check for infinity before zero */
if (MPFR_IS_INF(a))
- {
- MPFR_SET_INF(r);
- if(MPFR_SIGN(r) < 0)
- MPFR_CHANGE_SIGN(r);
- return 0;
+ {
+ if (MPFR_SIGN(a) < 0) /* log(-Inf) = NaN */
+ {
+ MPFR_SET_NAN(r);
+ MPFR_RET_NAN;
+ }
+ else /* log(+Inf) = +Inf */
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0);
+ }
}
/* Now we can clear the flags without damage even if r == a */
+ MPFR_CLEAR_INF(r);
- MPFR_CLEAR_INF(r);
+ if (MPFR_IS_ZERO(a))
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* log(0) is an exact infinity */
+ }
- if (MPFR_IS_ZERO(a))
+ /* If a is negative, the result is NaN */
+ if (MPFR_SIGN(a) < 0)
{
- MPFR_CLEAR_FLAGS(r);
- MPFR_SET_INF(r);
- if (MPFR_SIGN(r) > 0)
- MPFR_CHANGE_SIGN(r);
- /* Execption GMP*/
- return 0;
+ MPFR_SET_NAN(r);
+ MPFR_RET_NAN;
}
/* If a is 1, the result is 0 */
- if (mpfr_cmp_ui(a,1) == 0)
+ if (mpfr_cmp_ui(a, 1) == 0)
{
- MPFR_CLEAR_FLAGS(r);
- MPFR_SET_SAME_SIGN(r,a);
MPFR_SET_ZERO(r);
- return 0;
+ MPFR_SET_POS(r);
+ MPFR_RET(0); /* only "normal" case where the result is exact */
}
/* If a is integer, log2(a) is exact*/
diff --git a/pow_si.c b/pow_si.c
index 8646e1c13..0380b2fa7 100644
--- a/pow_si.c
+++ b/pow_si.c
@@ -1,6 +1,6 @@
/* mpfr_pow_si -- power function x^y with y an unsigned int
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -34,77 +34,47 @@ MA 02111-1307, USA. */
int
mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode)
{
-
- if (n>0)
- return mpfr_pow_ui(y,x,(unsigned long int)n,rnd_mode);
+ if (n > 0)
+ return mpfr_pow_ui(y, x, n, rnd_mode);
else
{
-
int inexact = 0;
- n=-n;
-
- /* x is NaN*/
- if (MPFR_IS_NAN(x))
+ if (MPFR_IS_NAN(x))
{
- MPFR_SET_NAN(y);
- return 1;
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
}
+
MPFR_CLEAR_NAN(y);
- /* n=0 */
- if(n==0)
- return mpfr_set_ui(y,1,GMP_RNDN);;
+ if (n == 0)
+ return mpfr_set_ui(y, 1, GMP_RNDN);
- /* case x is INF */
- if(MPFR_IS_INF(x))
+ if (MPFR_IS_INF(x))
{
- if(MPFR_SIGN(x)>0) /* +Inf */
- {
- MPFR_SET_ZERO(y);
- if(MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 0;
- }
+ MPFR_SET_ZERO(y);
+ if (MPFR_SIGN(x) > 0 || ((unsigned) n & 1) == 0)
+ MPFR_SET_POS(y);
else
- {
- MPFR_SET_ZERO(y); /* -Inf */
- if(!(n%2)) /* n is odd */
- {
- if(MPFR_SIGN(y) > 0)
- MPFR_CHANGE_SIGN(y);
- }
- else /* n is not odd */
- {
- if(MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- }
- return 0;
- }
+ MPFR_SET_NEG(y);
+ MPFR_RET(0);
}
- /* case x=0 */
- if(mpfr_cmp_ui(x,0) == 0)
+ if (MPFR_IS_ZERO(x))
{
- if(!(n%2)) /* n is odd */
- {
- MPFR_SET_INF(y);
- MPFR_SET_SAME_SIGN(y,x);
- DIVIDE_BY_ZERO; /* Execption GMP*/
- return 0;
- }
- else /* n is not odd */
- {
- MPFR_SET_INF(y);
- if(MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- DIVIDE_BY_ZERO; /* Execption GMP*/
- return 0;
- }
+ MPFR_SET_INF(y);
+ if (MPFR_SIGN(x) > 0 || ((unsigned) n & 1) == 0)
+ MPFR_SET_POS(y);
+ else
+ MPFR_SET_NEG(y);
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
+ n = -n;
+
/* General case */
{
/* Declaration of the intermediary variable */