diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-02-01 21:35:34 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-02-01 21:35:34 +0000 |
commit | 6e879c6f3361346ede165d0733a26e9145cccf69 (patch) | |
tree | ba27f0eb5a934b1be7da19ed5937cb8f7b076608 /log10.c | |
parent | d2a8d03f413280358567c13baa9b2e1f6e3349bf (diff) | |
download | mpfr-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
Diffstat (limited to 'log10.c')
-rw-r--r-- | log10.c | 64 |
1 files changed, 27 insertions, 37 deletions
@@ -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 */ |