diff options
author | enge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2010-10-04 15:46:25 +0000 |
---|---|---|
committer | enge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2010-10-04 15:46:25 +0000 |
commit | 4b78f79f94b6c654d43a3b8d1bebf8a4507568a4 (patch) | |
tree | 17c80e11db5d25ad3890d71054d51ce4a4d0f8b5 /src | |
parent | f6d3195ca2b74c70b848934dbcc8c30d0954193d (diff) | |
download | mpc-4b78f79f94b6c654d43a3b8d1bebf8a4507568a4.tar.gz |
use macro mpc_fin_p to detect special operands
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@847 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src')
-rw-r--r-- | src/cos.c | 2 | ||||
-rw-r--r-- | src/log.c | 2 | ||||
-rw-r--r-- | src/sin.c | 2 | ||||
-rw-r--r-- | src/sqr.c | 2 | ||||
-rw-r--r-- | src/sqrt.c | 120 | ||||
-rw-r--r-- | src/tan.c | 2 |
6 files changed, 66 insertions, 64 deletions
@@ -30,7 +30,7 @@ mpc_cos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) int inex_re, inex_im; /* special values */ - if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) + if (!mpc_fin_p (op)) { if (mpfr_nan_p (MPC_RE (op))) { @@ -31,7 +31,7 @@ mpc_log (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd){ int inex_re, inex_im; /* special values: NaN and infinities */ - if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) { + if (!mpc_fin_p (op)) { if (mpfr_nan_p (MPC_RE (op))) { if (mpfr_inf_p (MPC_IM (op))) mpfr_set_inf (MPC_RE (rop), +1); @@ -30,7 +30,7 @@ mpc_sin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) int inex_re, inex_im; /* special values */ - if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) + if (!mpc_fin_p (op)) { if (mpfr_nan_p (MPC_RE (op)) || mpfr_nan_p (MPC_IM (op))) { @@ -35,7 +35,7 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) mpfr_exp_t old_emax, old_emin, emin, emax; /* special values: NaN and infinities */ - if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) { + if (!mpc_fin_p (op)) { if (mpfr_nan_p (MPC_RE (op)) || mpfr_nan_p (MPC_IM (op))) { mpfr_set_nan (MPC_RE (rop)); mpfr_set_nan (MPC_IM (rop)); @@ -39,65 +39,67 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd) const int im_sgn = mpfr_signbit (MPC_IM (b)) == 0? 0 : -1; /* special values */ - /* sqrt(x +i*Inf) = +Inf +I*Inf, even if x = NaN */ - /* sqrt(x -i*Inf) = +Inf -I*Inf, even if x = NaN */ - if (mpfr_inf_p (MPC_IM (b))) - { - mpfr_set_inf (MPC_RE (a), +1); - mpfr_set_inf (MPC_IM (a), im_sgn); - return MPC_INEX (0, 0); - } - - if (mpfr_inf_p (MPC_RE (b))) - { - if (mpfr_signbit (MPC_RE (b))) - { - if (mpfr_number_p (MPC_IM (b))) - { - /* sqrt(-Inf +i*y) = +0 +i*Inf, when y positive */ - /* sqrt(-Inf +i*y) = +0 -i*Inf, when y positive */ - mpfr_set_ui (MPC_RE (a), 0, GMP_RNDN); - mpfr_set_inf (MPC_IM (a), im_sgn); - return MPC_INEX (0, 0); - } - else - { - /* sqrt(-Inf +i*NaN) = NaN +/-i*Inf */ - mpfr_set_nan (MPC_RE (a)); - mpfr_set_inf (MPC_IM (a), im_sgn); - return MPC_INEX (0, 0); - } - } - else - { - if (mpfr_number_p (MPC_IM (b))) - { - /* sqrt(+Inf +i*y) = +Inf +i*0, when y positive */ - /* sqrt(+Inf +i*y) = +Inf -i*0, when y positive */ - mpfr_set_inf (MPC_RE (a), +1); - mpfr_set_ui (MPC_IM (a), 0, GMP_RNDN); - if (im_sgn) - mpc_conj (a, a, MPC_RNDNN); - return MPC_INEX (0, 0); - } - else - { - /* sqrt(+Inf -i*Inf) = +Inf -i*Inf */ - /* sqrt(+Inf +i*Inf) = +Inf +i*Inf */ - /* sqrt(+Inf +i*NaN) = +Inf +i*NaN */ - return mpc_set (a, b, rnd); - } - } - } - - /* sqrt(x +i*NaN) = NaN +i*NaN, if x is not infinite */ - /* sqrt(NaN +i*y) = NaN +i*NaN, if y is not infinite */ - if (mpfr_nan_p (MPC_RE (b)) || mpfr_nan_p (MPC_IM (b))) - { - mpfr_set_nan (MPC_RE (a)); - mpfr_set_nan (MPC_IM (a)); - return MPC_INEX (0, 0); - } + if (!mpc_fin_p (b)) { + /* sqrt(x +i*Inf) = +Inf +I*Inf, even if x = NaN */ + /* sqrt(x -i*Inf) = +Inf -I*Inf, even if x = NaN */ + if (mpfr_inf_p (MPC_IM (b))) + { + mpfr_set_inf (MPC_RE (a), +1); + mpfr_set_inf (MPC_IM (a), im_sgn); + return MPC_INEX (0, 0); + } + + if (mpfr_inf_p (MPC_RE (b))) + { + if (mpfr_signbit (MPC_RE (b))) + { + if (mpfr_number_p (MPC_IM (b))) + { + /* sqrt(-Inf +i*y) = +0 +i*Inf, when y positive */ + /* sqrt(-Inf +i*y) = +0 -i*Inf, when y positive */ + mpfr_set_ui (MPC_RE (a), 0, GMP_RNDN); + mpfr_set_inf (MPC_IM (a), im_sgn); + return MPC_INEX (0, 0); + } + else + { + /* sqrt(-Inf +i*NaN) = NaN +/-i*Inf */ + mpfr_set_nan (MPC_RE (a)); + mpfr_set_inf (MPC_IM (a), im_sgn); + return MPC_INEX (0, 0); + } + } + else + { + if (mpfr_number_p (MPC_IM (b))) + { + /* sqrt(+Inf +i*y) = +Inf +i*0, when y positive */ + /* sqrt(+Inf +i*y) = +Inf -i*0, when y positive */ + mpfr_set_inf (MPC_RE (a), +1); + mpfr_set_ui (MPC_IM (a), 0, GMP_RNDN); + if (im_sgn) + mpc_conj (a, a, MPC_RNDNN); + return MPC_INEX (0, 0); + } + else + { + /* sqrt(+Inf -i*Inf) = +Inf -i*Inf */ + /* sqrt(+Inf +i*Inf) = +Inf +i*Inf */ + /* sqrt(+Inf +i*NaN) = +Inf +i*NaN */ + return mpc_set (a, b, rnd); + } + } + } + + /* sqrt(x +i*NaN) = NaN +i*NaN, if x is not infinite */ + /* sqrt(NaN +i*y) = NaN +i*NaN, if y is not infinite */ + if (mpfr_nan_p (MPC_RE (b)) || mpfr_nan_p (MPC_IM (b))) + { + mpfr_set_nan (MPC_RE (a)); + mpfr_set_nan (MPC_IM (a)); + return MPC_INEX (0, 0); + } + } /* purely real */ if (im_cmp == 0) @@ -33,7 +33,7 @@ mpc_tan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) int inex; /* special values */ - if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) + if (!mpc_fin_p (op)) { if (mpfr_nan_p (MPC_RE (op))) { |