summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exp.c14
-rw-r--r--pow_ui.c23
-rw-r--r--sin.c13
-rw-r--r--sinh.c12
-rw-r--r--tan.c15
-rw-r--r--tanh.c14
-rw-r--r--ui_pow.c19
-rw-r--r--ui_sub.c9
8 files changed, 52 insertions, 67 deletions
diff --git a/exp.c b/exp.c
index 185320886..12be08919 100644
--- a/exp.c
+++ b/exp.c
@@ -76,22 +76,12 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
x >= __mpfr_emax * log(2) */
d = mpfr_get_d (x);
if (d >= (double) __mpfr_emax * LOG2)
- {
- MPFR_SET_INF(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 1; /* overflow */
- }
+ return mpfr_set_overflow(y, rnd_mode, 1);
/* result is 0 when exp(x) < 1/2*2^(__mpfr_emin), i.e.
x < (__mpfr_emin-1) * LOG2 */
if (d < ((double) __mpfr_emin - 1.0) * LOG2)
- {
- MPFR_SET_ZERO(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 1; /* underflow */
- }
+ return mpfr_set_underflow(y, rnd_mode, 1);
/* if x < 2^(-precy), then exp(x) i.e. gives 1 +/- 1 ulp(1) */
if (expx < -precy)
diff --git a/pow_ui.c b/pow_ui.c
index 42a3ee3ee..0badba7e4 100644
--- a/pow_ui.c
+++ b/pow_ui.c
@@ -1,7 +1,7 @@
/* mpfr_pow_ui-- compute the power of a floating-point
by a machine integer
-Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+Copyright (C) 1999-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -20,7 +20,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 "mpfr.h"
#include "mpfr-impl.h"
@@ -46,24 +45,22 @@ mpfr_pow_ui (mpfr_ptr x, mpfr_srcptr y, unsigned long int n, mp_rnd_t rnd)
if (n == 0) /* x^0 = 1 for any x */
{
- mpfr_set_ui (x, 1, rnd);
- return 0;
+ /* The return mpfr_set_ui is important as 1 isn't necessarily
+ in the exponent range. */
+ return mpfr_set_ui (x, 1, rnd);
}
- if (MPFR_IS_INF(y))
+ if (MPFR_IS_INF(y))
{
/* Inf^n = Inf, (-Inf)^n = Inf for n even, -Inf for n odd */
if ((MPFR_SIGN(y) < 0) && (n % 2 == 1))
- {
- if (MPFR_SIGN(x) > 0)
- MPFR_CHANGE_SIGN(x);
- }
- else if (MPFR_SIGN(x) < 0)
- MPFR_CHANGE_SIGN(x);
+ MPFR_SET_NEG(x);
+ else
+ MPFR_SET_POS(x);
MPFR_SET_INF(x);
- return 0;
+ MPFR_RET(0);
}
-
+
MPFR_CLEAR_INF(x);
mpfr_init (res);
diff --git a/sin.c b/sin.c
index 8d625159c..9dd2b7ab0 100644
--- a/sin.c
+++ b/sin.c
@@ -1,6 +1,6 @@
/* mpfr_sin -- sine of a floating-point number
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
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"
@@ -34,13 +33,15 @@ mpfr_sin (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; /* inexact */
+ MPFR_RET_NAN;
}
- if (!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(x))
{
- mpfr_set_ui (y, 0, GMP_RNDN);
- return 0; /* exact */
+ MPFR_CLEAR_FLAGS(y);
+ MPFR_SET_ZERO(y);
+ MPFR_SET_SAME_SIGN(y, x);
+ MPFR_RET(0);
}
precy = MPFR_PREC(y);
diff --git a/sinh.c b/sinh.c
index 2646aad4b..fba85da0f 100644
--- a/sinh.c
+++ b/sinh.c
@@ -1,6 +1,6 @@
/* mpfr_sinh -- hyperbolic sine
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -31,7 +31,7 @@ MA 02111-1307, USA. */
*/
int
-mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
+mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode)
{
/****** Declaration ******/
mpfr_t x;
@@ -41,7 +41,7 @@ mpfr_sinh (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);
@@ -49,16 +49,16 @@ mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
{
MPFR_SET_INF(y);
MPFR_SET_SAME_SIGN(y,xt);
- return 0;
+ MPFR_RET(0);
}
MPFR_CLEAR_INF(y);
- if(!MPFR_NOTZERO(xt))
+ if (MPFR_IS_ZERO(xt))
{
MPFR_SET_ZERO(y); /* sinh(0) = 0 */
MPFR_SET_SAME_SIGN(y,xt);
- return(0);
+ MPFR_RET(0);
}
mpfr_init2(x,Nxt);
diff --git a/tan.c b/tan.c
index 3effc8749..aa2930488 100644
--- a/tan.c
+++ b/tan.c
@@ -1,6 +1,6 @@
/* mpfr_tan -- tangent of a floating-point number
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
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"
@@ -27,7 +26,7 @@ MA 02111-1307, USA. */
/* computes tan(x) = sign(x)*sqrt(1/cos(x)^2-1) */
int
-mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
+mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
int precy, m, ok, e, inexact;
mpfr_t c;
@@ -35,13 +34,15 @@ mpfr_tan (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; /* inexact */
+ MPFR_RET_NAN;
}
- if (!MPFR_NOTZERO(x))
+ if (MPFR_IS_ZERO(x))
{
- mpfr_set_ui (y, 0, GMP_RNDN);
- return 0; /* exact */
+ MPFR_CLEAR_FLAGS(y);
+ MPFR_SET_ZERO(y);
+ MPFR_SET_SAME_SIGN(y, x);
+ MPFR_RET(0);
}
precy = MPFR_PREC(y);
diff --git a/tanh.c b/tanh.c
index 4f0baa5ec..e1ef4a90f 100644
--- a/tanh.c
+++ b/tanh.c
@@ -1,6 +1,6 @@
/* mpfr_tanh -- hyperbolic tangent
-Copyright (C) 2001 Free Software Foundation.
+Copyright (C) 2001-2002 Free Software Foundation.
This file is part of the MPFR Library.
@@ -50,13 +50,13 @@ mpfr_tanh (y, xt, rnd_mode)
if (MPFR_IS_NAN(xt))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
if (MPFR_IS_INF(xt))
{
- if(MPFR_SIGN(xt) > 0)
+ if (MPFR_SIGN(xt) > 0)
return mpfr_set_si(y,1,rnd_mode); /* tanh(inf) = 1 */
else
return mpfr_set_si(y,-1,rnd_mode); /* tanh(-inf) = -1 */
@@ -64,17 +64,17 @@ mpfr_tanh (y, xt, rnd_mode)
MPFR_CLEAR_INF(y);
/* tanh(0) = 0 */
- if(!MPFR_NOTZERO(xt))
+ if (MPFR_IS_ZERO(xt))
{
MPFR_SET_ZERO(y);
MPFR_SET_SAME_SIGN(y,xt);
- return 0;
+ MPFR_RET(0);
}
-
+
mpfr_init2(x,Nxt);
mpfr_set(x,xt,GMP_RNDN);
- if(MPFR_SIGN(x)<0)
+ if (MPFR_SIGN(x) < 0)
{
MPFR_CHANGE_SIGN(x);
flag_neg=1;
diff --git a/ui_pow.c b/ui_pow.c
index ac3cb52dd..a247166fe 100644
--- a/ui_pow.c
+++ b/ui_pow.c
@@ -1,6 +1,6 @@
/* mpfr_ui_pow -- power of n function n^x
-Copyright (C) 2001 Free Software Foundation, Inc.
+Copyright (C) 2001-2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -31,14 +31,14 @@ MA 02111-1307, USA. */
*/
int
-mpfr_ui_pow (mpfr_ptr y, unsigned long int n,mpfr_srcptr x, mp_rnd_t rnd_mode)
-{
+mpfr_ui_pow (mpfr_ptr y, unsigned long int n, mpfr_srcptr x, mp_rnd_t rnd_mode)
+{
int inexact;
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
- return 1;
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
@@ -47,22 +47,19 @@ mpfr_ui_pow (mpfr_ptr y, unsigned long int n,mpfr_srcptr x, mp_rnd_t rnd_mode)
{
if (MPFR_SIGN(x) < 0)
{
+ MPFR_CLEAR_INF(y);
MPFR_SET_ZERO(y);
- if (MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 0;
}
else
{
MPFR_SET_INF(y);
- if(MPFR_SIGN(y) < 0)
- MPFR_CHANGE_SIGN(y);
- return 0;
}
+ MPFR_SET_POS(y);
+ MPFR_RET(0);
}
/* n^0 = 1 */
- if(mpfr_cmp_ui(x,0)==0)
+ if (MPFR_IS_ZERO(x))
{
return mpfr_set_ui(y,1,rnd_mode);
}
diff --git a/ui_sub.c b/ui_sub.c
index 144a9b942..65e96456c 100644
--- a/ui_sub.c
+++ b/ui_sub.c
@@ -1,6 +1,6 @@
-/* mpfr_ui_sub -- divide a machine integer by a floating-point number
+/* mpfr_ui_sub -- subtract a floating-point number from an integer
-Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+Copyright (C) 2000-2002 Free Software Foundation, Inc.
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 "longlong.h"
@@ -36,7 +35,7 @@ mpfr_ui_sub (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
- return 1; /* a NaN is inexact */
+ MPFR_RET_NAN;
}
MPFR_CLEAR_NAN(y);
@@ -46,7 +45,7 @@ mpfr_ui_sub (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode)
MPFR_SET_INF(y);
if (MPFR_SIGN(x) == MPFR_SIGN(y))
MPFR_CHANGE_SIGN(y);
- return 0; /* +/-infinity is exact */
+ MPFR_RET(0); /* +/-infinity is exact */
}
if (u) {