diff options
-rw-r--r-- | acosh.c | 4 | ||||
-rw-r--r-- | agm.c | 4 | ||||
-rw-r--r-- | asinh.c | 54 | ||||
-rw-r--r-- | atanh.c | 10 | ||||
-rw-r--r-- | copysign.c | 48 | ||||
-rw-r--r-- | cos.c | 6 | ||||
-rw-r--r-- | cosh.c | 17 | ||||
-rw-r--r-- | dim.c | 29 | ||||
-rw-r--r-- | div_ui.c | 22 | ||||
-rw-r--r-- | exp.c | 24 | ||||
-rw-r--r-- | exp2.c | 27 | ||||
-rw-r--r-- | expm1.c | 24 | ||||
-rw-r--r-- | hypot.c | 29 | ||||
-rw-r--r-- | log.c | 29 | ||||
-rw-r--r-- | log10.c | 64 | ||||
-rw-r--r-- | log1p.c | 43 | ||||
-rw-r--r-- | log2.c | 65 | ||||
-rw-r--r-- | pow_si.c | 78 |
18 files changed, 230 insertions, 347 deletions
@@ -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); @@ -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; } @@ -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); } @@ -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)); } @@ -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; @@ -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 */ { @@ -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); } } - @@ -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; @@ -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); @@ -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 */ { @@ -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 */ @@ -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 */ @@ -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); @@ -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 */ @@ -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 */ @@ -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*/ @@ -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 */ |