summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2010-10-04 15:46:25 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2010-10-04 15:46:25 +0000
commit4b78f79f94b6c654d43a3b8d1bebf8a4507568a4 (patch)
tree17c80e11db5d25ad3890d71054d51ce4a4d0f8b5 /src
parentf6d3195ca2b74c70b848934dbcc8c30d0954193d (diff)
downloadmpc-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.c2
-rw-r--r--src/log.c2
-rw-r--r--src/sin.c2
-rw-r--r--src/sqr.c2
-rw-r--r--src/sqrt.c120
-rw-r--r--src/tan.c2
6 files changed, 66 insertions, 64 deletions
diff --git a/src/cos.c b/src/cos.c
index 727d07f..01582da 100644
--- a/src/cos.c
+++ b/src/cos.c
@@ -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)))
{
diff --git a/src/log.c b/src/log.c
index 40cf508..77180f3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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);
diff --git a/src/sin.c b/src/sin.c
index 51dcd98..a197544 100644
--- a/src/sin.c
+++ b/src/sin.c
@@ -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)))
{
diff --git a/src/sqr.c b/src/sqr.c
index 9729b71..d55a5dd 100644
--- a/src/sqr.c
+++ b/src/sqr.c
@@ -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));
diff --git a/src/sqrt.c b/src/sqrt.c
index 8d3653d..95c8459 100644
--- a/src/sqrt.c
+++ b/src/sqrt.c
@@ -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)
diff --git a/src/tan.c b/src/tan.c
index 9b3498b..d730a06 100644
--- a/src/tan.c
+++ b/src/tan.c
@@ -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)))
{